Consume jpeg/png/PDF files from the REST API
Application Type
Mobile, Reactive

Hi all,

I am trying to consume a REST API that sends images or pdf files as part of the response.

Example:

{

  "id": 23533,

  "objectAvailable": true,

  "discontinued": false,

  "attachment": "ew0KICAiZGVmaW5pdGlvbkpTT04iIDogew0KICAidGFyZ2V0UmVzb3VyY2UiIDogImFjdGlvbiIsDQogICJ0YXJnZXRDbGFzcyIgOiBudWxsLA0KICAibWFwcGluZyIgOiBbIHsNCiAgICAiZmllbGQiIDogImJyZWFrIiwNCiAgICAic2VhcmNoZXMiIDogWyBdLA0KICAgICJkZWZhdWx0VmFsdWUiIDogew0KICAgICAgInNob3J0Q29kZSIgOiBudWxsLA0KICAgICAgImNzZ1Nob3J0Q29kZSIgOiBudWxsDQogICAgfSwNCiAgICAic2VhcmNoUmV0dXJuRmllbGRzIiA6IFsgXSwNCiAgICAic2VhcmNoUmV0dXJuQ29"

  "fileName": "datamapper_Email-Action.json",

  "linkedObjectId": 10193323

}


Now, how will I fetch the attachment as a binary file?


The response I get is as text. Please advise.

Hi Abira,

Have you tried using the TextToBinaryData action from the BinaryData library?

It's expected that the binary data is transferred as Text (converted from Binary). You might need to convert it back to Binary according to your use case.

mvp_badge
MVP

In addition to @Ozan Cali's response, it looks like the image is base64 encoded. If you are trying to save it, then you will need to use Base64ToBinary as well.

Or, if you just want to display it on the screen, you can actually set the base64 data right into an image by setting the img tag's src attribute to

data:image/png;base64, BASE64DATAGOESHERE

Hi Abira,

Use "base64tobinary" server action to convert your base64 file to binary data.

Thanks

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.