+ Start a Discussion
Leafen SandyLeafen Sandy 

Does apex support rest api for multipart/form-data requests made from external system

If there is a possiblity, then

Can I get a code sample (having @http post method) on how to upload pdf file into salesforce object (say as an attachment) sent to salesforce with a http request using multipart/from-data from some external site.

For a while I've gone through multipart/form-data in the developer forum, but I could only find the HTTP Request samples made from salesforce and not to salesforce.

Raj VakatiRaj Vakati
Yes .. It Suports 

Refer this link 

Leafen SandyLeafen Sandy
Hi Raj,

Thanks for your reply.

I've gone through both of these links(even already) and I guess there they are just making a http request from salesforce to a external location.

But I actually want to write a  RESTful Web service Apex class (@RestResource(urlMapping='/url/')) to receive the request sent from an external system.

I've written it many times before but not sure what kind of change should I do to handle a request having multipart/form-data as a content type in its header.


User-added image

Even in the above link, one of the answer is like its not supported.

So just want to know, is it still not supported or is there an update on that.

Alok Singh 140Alok Singh 140
Follow This blog.
Fabian Manzano 6Fabian Manzano 6
From my knowledge it does not support, if you have control in the inbound call, what I do is encode this way when i receive the API I decode it:
Attachment a = new Attachment();
a.Name = 'xxxx';
a.Body = EncodingUtil.base64Decode('xxx');
a.ParentId = 'xxxx';

Muralidhar Sampathirao 10Muralidhar Sampathirao 10

Here is a solution using which we can create a custom Apex REST service to accept multipart/form-data requests