Last active
November 16, 2024 22:05
-
-
Save z11i/fdd874573fc4956c3ee3aad164eddbfe to your computer and use it in GitHub Desktop.
Use curl to upload a file in a multipart/form-data request, with custom content-type for the file (not the request)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
filename='yourfilename' | |
filetype='text/csv' | |
token='my oauth token' | |
url='http://localhost/upload' | |
curl "$url" \ | |
--form "data=@$filename;type=$filetype" \ | |
--form "name=somename" \ | |
-H "Authorization: Bearer $token" | |
Thank you so much for this! Scoured the entire internet until I found a simple explanation as to why all my requests were denied.
You sir, are a gentleman and a scholar, thanks!
thanks, that saved me quite the headache!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This generates the below HTTP request:
Note that there's another
Content-Type
in the multipart request's body. It's different from the multipart request itself. ThisContent-Type
is specified using thetype=
part in the--form
header. If you didn't specify this, a default content type would beapplication/octet-stream
(i.e. a binary file).The
curl
command generated from Postman is almost always wrong, as Postman relies on Chromium to do the multipart handling.