cancel
Showing results for 
Search instead for 
Did you mean: 

REST Post Multipart Form-Data + File Upload Issue

whaleyl
New Contributor III

I’m having trouble correctly formatting multipart form-data to be sent as the body of a REST Post request along with a single file upload.

I’ve managed to get the Post request to correctly send in Postman with the required key/value pairs and a test file:

Postman

However, when attempting to replicate this in SnapLogic I am unsuccessful.

I’ve managed to correctly map the key/value pairs in a mapper, and have created the following JSON in a JSON generator using my mapped values:

JSONGenerator

I’ve used my “entity” object as the HTTP entity in my Post request, and pointed to a local test file for upload in my REST Post snap:

PostSnap1
PostSnap2

Is my approach to compiling the form-data correct, or no?

10 REPLIES 10

I’ve resolved the issue with help from another SnapLogic community page. See https://community.snaplogic.com/t/rest-post-with-form-params-in-the-body-of-the-request-giving-error....

I changed the Content-Type to expect: application/x-www-form-urlencoded (rather than multipart/form-data) and I serialized the body using the expression: $.entries().map(e => e[0] + “=” + encodeURIComponent(e[1])).join(“&”), which I passed into the HTTP entity field in the REST Post. I can now make a successful request.