You need to sign in to do that
Don't have an account?

http callout with multipart/form-data
Hi,
I am trying to make HTTP POST request with multipart/form-data, the problem is that the request is sent but without the body part. I was trying the solution: http://enreeco.blogspot.it/2013/01/salesforce-apex-post-mutipartform-data.html, but it doesn't worked for me. I think it is the same problem as: http://boards.developerforce.com/t5/Apex-Code-Development/Image-upload-using-multipart-form-data/m-p/243335/highlight/true#M42610. Will this issue be solved? Is there any alternative to HttpRequest?
footer = '\r\n--'+formBoundary+'--',
headerForm = '--'+formBoundary+'\r\nContent-Disposition: form-data; name="{0}";\r\n\n',
headerFile = '--'+formBoundary+'\r\nContent-Disposition: form-data; name="{0}"; filename="{1}";\r\nContent-Type: {2}\r\n\n';
string documentHexContent = EncodingUtil.convertToHex(blob.valueOf((string.format(headerForm, new list<String> {'document'})+
<XML content>)));
string fileHexContent = EncodingUtil.convertToHex(blob.valueOf('\r\n'+string.format(headerFile, new list<String> {'filename',fileName,'application/pdf'})))+
EncodingUtil.convertToHex(<PDF file>)+
EncodingUtil.convertToHex(blob.valueof(footer));
HttpRequest req = new HttpRequest();
req.setMethod('POST');
req.setEndpoint('<resource URL>');
req.setHeader('Accept', '<Accept content type>');
req.setHeader('Content-Type', 'multipart/form-data; boundary='+formBoundary);
req.setBodyAsBlob(body);
req.setHeader('Content-Length',string.valueOf(req.getBodyAsBlob().size()));
HttpResponse resp = new Http().send(req);
Please advise if you have any solution.
Thanks,
Hello foundation_dev
what you are looking for is not supported by the salesforce apex callout. it's still in the salesforce Idea Exchange here is the link for the same.
https://trailblazer.salesforce.com/ideaView?id=08730000000Kr80AAC
You can vote for it but currently, multipart/form-data header is not supported.
please mark as solved if your issue is resolved