We are having troubles with creating file objects on the server side. This code works in the client:
const decodedData = atob(base64);
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' });
return blob;
However, when we try to run this in a service we get the error: Blob is not defined.
We have also tried to run atob(base64) (as demonstrated in Showroom) but this only produces blank files.
What is the correct way to create files from base64 in services?
I would be interested to see more of the atob(base64) setup - I have functionality in a customer application which works using this setup, acting as an endpoint that receives base64 file content from an external source.
See the screenshots below, where the base64 string for a PDF file and CSV file are a part of a JSON payload:
If the base64 string is resulting in an empty file, maybe the problem is with the base64 string itself? Are you using the example shown in the Showroom to generate base64 content?
I have sent you a DM with link to our set up.
Some files are working while others will only produce blank files, even though the same base64 produce the correct file from the client while using BLOB.