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

How to read pdf, doc or ppf file content and send through Rest API

Hi All,


I am trying to upload file through Rest API. i am able to upload and extract text files properly but if i upload any other file format (pdf,doc ,ppt or any image) , the file uploads fine but if i try to open that file it won't open( error message : file is broken , or the pdf is blank). It seems the file body i am sending is not properly encoded for other file formats.

Below is my code which i am using to upload files

String ObjectName = input.filename;
System.debug('ObjectName' + ObjectName);
Blob BodyContent=input.fileBody;
String DocBody = BodyContent.toString();
// String DocBody = EncodingUtil.base64Encode(BodyContent);
// String DocBody = EncodingUtil.urlEncode(bodyContent.toString(), 'UTF-8');
// String DocBody1 =
System.debug('DocBody' + DocBody);
Integer bodyLength =DocBody.length();
System.debug('bodyLength ------------->' + bodyLength );

String url6=input.StorageURL;
Http h6 = new Http();

HttpRequest req6 = new HttpRequest();
req6.setEndpoint(url6 + '/' + input.containerName + '/'+input.objectPath + '/' + ObjectName );//

// System.debug('Request object is----------->' + req6);
HttpResponse res6;
res6 = h6.send(req6);
if i upload a file directly to storage size is 15Kb but if i upload through API file size is showing 24 KB.

Please let me know do i need to encode the file body or am i missing any thing.

I have tried with encloding also but still no luck

Quick response would be appreciated!!

Chirag MehtaChirag Mehta

Where you able to successfully upload pdf,docfiles through RESTAPI?


Nope, i am still looking for the solution

Chirag MehtaChirag Mehta

same here. Thanks!



Were you guys able to bulk upload the files.





Any new insights considering this topic?

SFDC MobileSFDC Mobile

I came across one app that does this job greatly, allows to drag and drop and attach multiple files.  Drag, Drop & Attach Multiple Attachment


PS : However, the caveat is that its PAID