You need to sign in to do that
Don't have an account?
AMRITA AGARWALA 2
Convert Salesforce Attachment.Body to a file in javascript
Hi,
I have received the Attachement.Body from REST API call as mentioned in https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_sobject_blob_retrieve.htm from client side.
When I get the blob returned and try to create a js file object,as below:
var body = [blobData];
this.file = new File(body , fileName , {type: contentType , lastModifiedDate: new Date(), name: fileName} );
Now btoa(blobData) throws error Uncaught DOMException: Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range for image/pdf. It works fine for text.
Please help to figure this out.
I have received the Attachement.Body from REST API call as mentioned in https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/resources_sobject_blob_retrieve.htm from client side.
When I get the blob returned and try to create a js file object,as below:
var body = [blobData];
this.file = new File(body , fileName , {type: contentType , lastModifiedDate: new Date(), name: fileName} );
Now btoa(blobData) throws error Uncaught DOMException: Failed to execute 'btoa' on 'Window': The string to be encoded contains characters outside of the Latin1 range for image/pdf. It works fine for text.
Please help to figure this out.
I am trying to achieve the same functionality, Can you please help me with sample code.
Thank you in advance
I'm getting An invalid XML character (Unicode: 0x8) was found in the element content of the document. error if I'm using (unescape(encodeURIComponent(blobData))) ;
And blank PDF is generating if I'm using btoa(unescape(encodeURIComponent(data)));
Please help me with this.
1. convert attachment.Body into base64 data (in Apex code)
2. convert base64 data into blob data (in Javascript)
I tried with this and it works perfectly. Sample code for this solution is
1. in Apex code:
2. in Javascript: