• AMRITA AGARWALA 2
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 3
    Replies
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. 
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. 
This is my code:
public class AccountHandler {

    public static Account insertNewAccount(String name){
        try{
            Account acc = new Account();
            acc.Name = name ; 
            insert acc ; 
            system.debug(acc.Id);
            return acc;
            
        }catch (DmlException e) {
           System.debug('A DML exception has occurred: ' + e.getMessage());
           return null; 
        }
    }
}
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. 
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.