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?