You need to sign in to do that
Don't have an account?
Tina0204
How to send additional parameters in multipart/form data
Hi guys,
I have a use case for REST integration where in I am doing a POST request and sending the json file in the REST request. I am sending the filename as a parameter.
Is it possible to send an additional parameter along with the file name in another key valye pair?
Like the below JS snippet -
formData: { "file": fs.createReadStream("payload.json") "job_type": "property-details", },
I need to send that additional "job_type" : "property=details" along with the file name. Is it possible to do?
I have a use case for REST integration where in I am doing a POST request and sending the json file in the REST request. I am sending the filename as a parameter.
Is it possible to send an additional parameter along with the file name in another key valye pair?
Like the below JS snippet -
formData: { "file": fs.createReadStream("payload.json") "job_type": "property-details", },
I need to send that additional "job_type" : "property=details" along with the file name. Is it possible to do?
Review below snippet and links that might helpful and give you more information.
Snippet:
=======
HttpRequest req = new HttpRequest();
req.setHeader('Content-Type','multipart/form-data; boundary='+boundary);
req.setMethod('POST');
req.setEndpoint('http://posttestserver.com/post.php?dir=watchdox');
req.setBodyAsBlob(bodyBlob);
req.setTimeout(60000);
req.setHeader('Content-Length',String.valueof(req.getBodyAsBlob().size()));
Http http = new Http();
HTTPResponse res = http.send(req);
return res;
Links:
=====
https://salesforce.stackexchange.com/questions/211477/multipart-form-data-post-file-with-multiple-form-parameters
https://github.com/MetaMind/apex-utils/blob/master/HttpFormBuilder.apex
https://blog.enree.co/2013/01/salesforce-apex-post-mutipartform-data.html
https://salesforcetrail.blogspot.com/p/upload-file-using-multipartform-data.html
https://salesforcetrail.blogspot.com/p/upload-file-using-multipartform-data.html
Hope above information was helpful.
Please mark as Best Answer so that it can help others in the future.
Thanks,
Vinay Kumar