Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

curl - Sending multipart/mixed content with Postman Chrome extension

I'm struggling with creating POST multipart/mixed request with Postman Chrome extension

Here is my curl request what works nice

curl -H "Content-Type: multipart/mixed" 
-F "metadata=@simple_json.json; type=application/json "
-F "content=@1.jpg; type=image/jpg" -X POST http://my/api/item -i -v

interesting part of response

Content-Length: 41557

Expect: 100-continue

Content-Type: multipart/mixed; boundary=----------------------------8aaca457e117

  • additional stuff not fine transfer.c:1037: 0 0
  • HTTP 1.1 or later with persistent connection, pipelining supported

And when I use Postman enter image description here

I getting such response

{"message":"Could not parse multipart servlet request;
 nested exception is org.apache.commons.fileupload.FileUploadException: 
 the request was rejected because no multipart boundary was     
 found","type":"error","status":500,"requestId":"1861eloo6fpio"}

That's it - I wish to get rid of that error. If some more information needed please ask :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I was facing this problem too. Short answer: remove the Content-Type header from your Postman request.

The long story is that the Content-Type for a multipart request should be rather special -- it should look kind of like this:

multipart/form-data; boundary=----WebKitFormBoundaryzeZR8KqAYJyI2jPL

The problem is that the boundary is important and it needs to exactly match the boundary used to separate the files being uploaded. The solution is simple: do not specify a Content-Type! When you upload files, Postman will automatically append the above content type for you, except the boundary will be filled in with whatever Postman or Chrome is using to separate the multipart content.

You can verify this behavior by using Chrome developer tools (within Postman) to examine the Content-Type header being added, in addition to the Content-Disposition headers of the multipart data, which are also a pain to construct manually (and impossible within Postman).

Note: My answer is a solution for those who need a multipart/form-data answer. The OP was looking for a multipart/mixed solution. My answer will not suffice in this scenario. That being said, it seems a lot of people just want the multipart/form-data solution, so I will leave my answer here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...