-
Notifications
You must be signed in to change notification settings - Fork 1k
Open
Labels
Description
When I use the curlconverter to convert a complex curl command to JSON, specifically a command that uploads multiple files using the same form field name (key), the JSON output doesn't capture all the files. Instead, it overwrites the previous file with the last one having the same key.
Example
curl -F files=@picture1.jpg -F files=@picture2.jpg -F "story=<hugefile.txt" --form-string "name=content" example.com/upload.cgiOutput
{
"url": "http://example.com/upload.cgi",
"raw_url": "http://example.com/upload.cgi",
"method": "post",
"files": {
"files": "picture2.jpg",
"story": "hugefile.txt"
},
"data": {
"name": "content"
}
}
Demonstrating the Problem with JavaScript:
When converting to other languages or libraries, such as JavaScript's Fetch API, multiple files for the same key are handled correctly:
const form = new FormData();
form.append('files', File(['<data goes here>'], 'picture1.jpg'));
form.append('files', File(['<data goes here>'], 'picture2.jpg'));
form.append('story', File(['<data goes here>'], 'hugefile.txt'));
form.append('name', 'content');
fetch('http://example.com/upload.cgi', {
method: 'POST',
body: form
});As illustrated, the correct approach involves using multiple entries for each file under the files key.
Reactions are currently unavailable