Sending multipart/form-data content with Postman Chrome extension
Asked Answered
F

0

8

I'm struggling with creating POST multipart/mixed request with Postman Chrome extension. I keep getting HTTP 500.

Already gone through this question, but sadly solution doesn't works for me.

Here is my curl request which works for me.

curl -H "Content-Type: multipart/form-data" -F "[email protected]; type=image/png" -F "[email protected]; type=application/json" -X PATCH localhost:5000/api/merchants/57035bda0c74362faf5937f2/details -i -v

And when I use Postman enter image description here

I am getting such response

{"code": 500,
"message": "There was an error processing your request. It has been logged (ID 034bec7815baca2e)."}

Request headers being passed from postman. Request headers from Postman

Somehow, the merchantDetails are always being passed as null when calling from POSTMAN and is passed properly when making call from curl.

Any help would be much appreciated.

EDITED 1:

My request from POSTMAN copied as curl,

curl 'http://localhost:5000/api/merchants/5714d8e060b2a79e62227d1a/details' -X PATCH -H 'Pragma: no-cache' -H 'Origin: chrome-extension://fdmmgilgnpjigdojojpjoooidkmcomcm' -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-GB,en-US;q=0.8,en;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36' -H 'Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryxRZ6VKzFV40ZFIsd' -H 'Accept: /' -H 'Cache-Control: no-cache' -H 'Cookie: JSESSIONID=1ofut8bbydk491k2s80i4rowed; JSESSIONID=yg4l9zpjs5oj1xaqnuo44ehp6' -H 'Connection: keep-alive' --data-binary $'------WebKitFormBoundaryxRZ6VKzFV40ZFIsd\r\nContent-Disposition: form-data; name="merchantDetails"; filename="merchant.json"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n------WebKitFormBoundaryxRZ6VKzFV40ZFIsd\r\nContent-Disposition: form-data; name="merchantLogo"; filename="offerlogo-320-320.png"\r\nContent-Type: image/png\r\n\r\n\r\n------WebKitFormBoundaryxRZ6VKzFV40ZFIsd--\r\n' --compressed

Frost answered 11/4, 2016 at 5:50 Comment(9)
Could you try opening up Chrome Developer Tools and open up the network tab and include the request headers that were sent when you clicked "Send"?Marketplace
@KirkWoll Added request headers being sentFrost
Honestly, I hadn't responded 'cause I was kind of stumped. But try this: with Chrome Developer Tools open, and the network tab open, after making the request in Postman, right-click on the request in the network tab and choose "Copy as cURL (bash)" and edit your question to include that data. That might give us a good apples to apples comparison between the curl command that works and the one that doesn't. (though honestly not sure how that copy command will work with file attachment data...)Marketplace
Also, the server you are using -- does it have any verbose logging option? It is clearly failing to accept your Postman command and the reasons remain unclear. Your headers look great, but ideally the server would provide some details of what precisely was wrong with your request. Also, what Http Method are you using? I assume PATCH? (wasn't visible in the screenshot)Marketplace
@KirkWoll Added the postman request being copied as curl. It seems that problem is with ContentType of json file being passed which is application/octet-stream. But it should be application/json.Frost
Yes, my request is PATCH, and yes the server also has verbose logging option but the problem is that merchantDetails being passed from request are null, hence I get a NullPointerExceptionFrost
Hmm, I Postman on both my Mac and Windows. Windows passed application/octet-stream and the Mac passed application/json. Not sure why that's behaving differently -- my hunch is that Chrome is the one supplying the content-type and it behaves differently on different OSs. Is there anything you can do on the server to make it less strict about the content-types of the form parts?Marketplace
I don't want to make my API less strict only because POSTMAN doesn't works for me. This seems to be issue on POSTMAN. Since curl works fine for me.Frost
This seems to be bug(or unsupported feature) in POSTMAN, I have raised this long ago, but still no success.Frost

© 2022 - 2024 — McMap. All rights reserved.