Skip to main content

My quesstion

How do I extract the base64 data from embedded images within freshdesk tickets?

Context

The images are hosted on freshdesk with a link such as https://attachment.freshdesk.com/inline/attachment?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6OTIwMjE0MDI3NywiZG9tYWluIjoiY2lyY3VtZmxleC5mcmVzaGRlc2suY29tIiwiYWNjb3VudF9pZCI6MzAwOTIzfQ.B3CzU2v9lyl4dq7uW6XEjF_oK5IPt__HCKN58RJDNMk . When getting those images, I get a byte stream. That is convertible to base64 data by using a byte to ascii function. This should all work in theory, but in practise I can’t make it work.

Goal

Replace tickets’ images with their base64 data, to upload on another service:

<img src="https://attachment.freshdesk.com/inline/attachment?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6OTIwMjE0MDI3NywiZG9tYWluIjoiY2lyY3VtZmxleC5mcmVzaGRlc2suY29tIiwiYWNjb3VudF9pZCI6MzAwOTIzfQ.B3CzU2v9lyl4dq7uW6XEjF_oK5IPt__HCKN58RJDNMk " data-id="9198554508" alt="image.png" width="562" height="181">

<img src="data:image/png;base64, iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" data-id="9198554508" alt="image.png" width="562" height="181"/>

Progress

I can download the image's data in which I assume is byte data, convert it to ascii (which I assume is the base64 format).

pm.sendRequest(link, (err, res) => {
err ? reject(err)
: resolve({link, raw: res.text(), imageData: btoa(res.text())});
});

When uploading that to https://base64.guru/converter/decode/file to check it, it turns out the data isn’t readable. Your browser cannot display the file as “application/octet-stream”.  even though the response tells me the data is content-type: image/png

 

Any ideas how I can progress from here?

Greetings @Michiel Doorn. Thanks for reaching Freshworks community. 

I understand you are attempting to transform the embedded images into Base64. Regrettably, Base64 and ASCII are not the same. You may utilize any of the available online platforms to convert the images to the Base64 format, or you can collaborate with your team to create a script that converts the image to Base64. Would you kindly attempt converting the image to Base64 instead of ASCII and verify if that resolves the issue?

Thank you,

Sujitha.


Reply