Reputation: 12177
I am working with file uploads and I would like to be able to send some extra data with the file if possible, this is the request I am currently working with...
curl -vX POST [URL] -F "file=@filepath"
but it would be nice if I could send some extra data with the file, like a comment...(would be nice if this worked)
curl -vX POST [URL] -F "file=@filepath&comment=this is a comment"
I would rather not enforce an order of file, comment, file, comment at the application level by doing this...
curl -vX POST [URL] -F "file=@filepath" -F "comment=this is a comment"
is there any way to include the comment with the first file instead of in a different field of the request?
Upvotes: 0
Views: 128
Reputation: 57994
(ditch the -X POST
, it's not helpful)
$ echo "comment=this is a comment" | cat - filepath | curl -F file=@- [URL] -v
The '-' option to cat makes it read from stdin first.
Note that this comment will appear as part of the file to the receiver so the receiver need to know how to extract it somehow.
I think it is crazy to cram them into the same field when it is so much easier for both the receiving end as well as the sender to have them in one field each:
curl -F file=@filepath -F "comment=this is a coment" [URL]
Upvotes: 1