Multiple fields in one multipart/form-data request part
See original GitHub issueI am trying to use requestslibrary to upload some files, goal is to achieve this:
------WebKitFormBoundary61N9vqJ7380nh6iv
Content-Disposition: form-data; name="files"; filename="photo-2.jpeg"
Content-Type: image/jpeg
------WebKitFormBoundary61N9vqJ7380nh6iv
Content-Disposition: form-data; name="fileId"
b3duLWZpbGVzL2ZmZmZmZmZmYTQyNDVmODAvMjAxNTY*
------WebKitFormBoundary61N9vqJ7380nh6iv
Content-Disposition: form-data; name="extract"
false
------WebKitFormBoundary61N9vqJ7380nh6iv--
and now I have this:
${data}= Evaluate {'files': open("C:/testautomation/resources/Assets/photo-2.jpeg", 'r+b'), 'extract': (None, 'false'), 'fileId': (None, 'b3duLWZpbGVzL2ZmZmZmZmZmYTQyNDVmODAvMjAxNTY*')}
${result}= Post Request rest ${url} headers=${HEADERS} files=${data}
I THINK that the only bit I am missing is the “Content-Type: image/jpeg” from the first part, but how on earth I can add that? Currently the file gets uploaded, but it is not considered to be a image file.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
multipart/form-data and multiple fields with the same name #737
I'm sending a POST request with multiple fields with the same name which normally works well when passed in a dict: >>> from...
Read more >HTTP multipart/form-data multiple files in one <input>
According to W3c, multiple files selected in a <input> field, should be send by "multipart/mixed" type with separate boundary string and only ...
Read more >Create a multipart fom data to send multiple field...
HI, we are struggling with creating a multiple-fileds multipart formdata to send to some APIs. After a lot of frustration with natve policies,...
Read more >Multipart Request Handling in Spring - Baeldung
Multipart requests consist of sending data of many different types separated by a boundary as part of a single HTTP method call.
Read more >How to upload file with a form with multiple fields — oracle-tech
With multipart/form-data as the name suggests your form-data contains multiple parts meaning one or more files and some form fields.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@lucagiove what if the multiple parts are not all files?
Here the requests library assumes both are files, I am assuming because I used the
files
argument. But if I try withdata
as init does not seem to know the first is a file. Nor does it seem to build up the multipart data request.
I have the same requirement as @emanlove, robotframwork don’t support multiple parts that are not all files. I got the below error: The server cannot or will not process the request, only one file support