+ Start a Discussion
Madhusudan Singh 19Madhusudan Singh 19 

Post blob data from Salesforce to Sharepoint


I am integrating salesforce with SharePoint where I have to send files directly to SharePoint from the browser without creating File/Attachment inside salesforce.

With the SharePoint REST API, I am able to create a file in Sharepoint but when I download the file, it is corrupted.
If the uploaded file is of PNG type then once it is uploaded if we view it image content is incomplete and colors are faded.
If we upload pdf file then some portion of pdf will be missing after upload.

But when I create an Attachment with the same base64 encoded string, I am able to view the complete and correct file.
public static void createFileInSharepoint(String fileName, Blob fileContent, String folderName){
	HttpRequest req = new HttpRequest();
	request.setHeader('Content-Length', String.valueOf(req.getBodyAsBlob().size()));
	Http http = new Http();
	HTTPResponse res = http.send(req);

I went through multiple blogs, but many articles are old and not working anymore.

Please help.

Madhusudan Singh
ShivankurShivankur (Salesforce Developers) 

Hi Madhusudan,

Please check out the latest suggestions posted in below thread, if it helps you make it more better:

Hope above information helps. Please mark as Best Answer so that it can help others in future.