function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AMRITA AGARWALA 2AMRITA AGARWALA 2 

storing the blob received by Attachment.Body does not give desired result

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 using Ajax call given by salesforce javascript sdk.  
Then I try to insert the blob(say for image file) to the database using javascript file object shown below: 
    var body = [blobData];
    this.file = new File(body , fileName , {type: contentType , lastModifiedDate: new Date(), name: fileName} );
   //code to insert this.file to my server. 
After inserting if I try to view this file(image) I cant view it. It throws error. For pdf a blank pdf is getting stored. 
I tried to convert this blobData to base64 then back to blob and tried other things also but no luck. 
please help me to figure it out. 
pconpcon
Have you tried creating your body with the Blob object before passing it to the file constructor?  Are you doing this inside of something like node? 
AMRITA AGARWALA 2AMRITA AGARWALA 2
 I have tried that. Does not work.
pconpcon
Where are you running this code from?