+ Start a Discussion
Laxman Vattam 26Laxman Vattam 26 

Sending File body from Salesforce to Sharepoint using REST API

Requirement: We have a requirement to download a particular version of file (contentVersion: using the versiondata field on contentversion) and upload this docuement to sharepoint. Documents can be of any type. For e.g. PDF, Doc, CSV, Png, txt etc. -

Problem Statement:  We are able to read the content version data from contentversion object. But Salesforce encodes the document into the binary file while storing it into Salesforce. While uploading the document(via REST integration) into SharePoint, we are not able to decode the binary file into the actual file stored and hence the uploaded document is not opening in SharePoint site with following error “Failed to load the document. 

Many solutions in forums suggest to use EncodingUtil.base64Decode(inputString) or convertToHex(inputBlob) but these conversions are failing with error message (Not a valid UTF 8 character or  Illegal hexadecimal character � at index )

Can someone shred some light on how to convert this before sending to sharepoint so that is is in readable format?
sfdc org 1sfdc org 1
Hi Laxman,

Have you solve the issue?

I am having same requirenment but not able to finish my task. Any lead will be great help for me.

Thanks.
Laxman Vattam 26Laxman Vattam 26
//get content from Salesforce as blob res2 = http2.send(req2); blob s2 = res2.getBodyasblob(); //send content as blob when sending to SharePoint req5.setBodyasblob(s2);