Receiving PDF-file from b64-string

Hi. I’m trying to recieve a PDF-file from a web-request and them insert it into a file-object in Appfarm using the custom file content choice:

I have tested the base64-string in this converter: Base64 to File | Base64 Decode | Base64 Converter | Base64
and it gives me the right PDF output. I get no error when making the file, however the built in PDF-dispay component says “Can’t load data”. I think there might be a conversion issue - so I need the right conversion, but have not yet been able to find one that works.

The PDF-file in Base64-format: (“JVBERi0xLjUKJVBERi0xLjUK…”).
Can send the whole string if needed.

Best Regards,
Fridtjof

Hi!

We have a challenge registered on this one.

The issue is that in Services, the atob/btoa are hardcoded to utf8. Also, we have some idications that there are some similar encoding issues when using “Create file object” in Services from binary data.

Will get back to you when it has been analyzed a bit further in order to give a more precise feedback (incl estimate of completion)

Hi. Thanks!

For now I have created a workaround using coded component.

Hi,
Is there any updates on this? I’m having issues with decoding the base64 pdf. When opening the downloaded file I get an error, even though the base64 string is correct.

Hi, we are also awaiting this feature :raising_hand_man:

1 Like

Hi Fridtjof,

Are you able to share how you solved this issue with at coded component?

Hi!

Just been having a discussion with the Engineering team. This issue is part of a bigger intitiative on binary files and convertions. The work spans several aspects, and most of it hopefully to be completed Q3. Until then, alternative methods need to be used (via third parties, or maybe it may be solved with pure javascript in services as well)

2 Likes

Hi! I had a similar use case and solved it this way:

  1. Got the base64 string with a web request and stored it in an app variable (base64String)
  2. Added a button where the user can download the PDF
  3. Added a run code action when the button is clicked with this code:
const decodedData = atob(base64String);
const arrayBuffer = new ArrayBuffer(decodedData.length);
const uint8Array = new Uint8Array(arrayBuffer);

for (let i = 0; i < decodedData.length; i++) {
  uint8Array[i] = decodedData.charCodeAt(i);
}

const blob = new Blob([arrayBuffer], { type: 'application/pdf' });
const blobURL = URL.createObjectURL(blob);

const link = document.createElement('a');
link.href = blobURL;
link.download = "filename.pdf";
link.click();
resolve()