5

When uploading a file with curl's --upload-file option, how do I specify a file name different than the one on disk? With the -F option, it can be done like this, I think: curl -F 'file=@/path/to/file/badname;filename=goodname', but I'm not sure how to do the equivalent with --upload-file (also -T). I am using an API which requires an uploaded file to have a certain filename, but I don't want to copy the file on-disk just so I can upload it properly.

4 Answers 4

1

Try this:

curl URL>/goodname --upload-file badfilename

Example:

curl http://example.com/goodname.html --upload-file badfilename.html

I tried this and managed to upload a file called goodname.html :)

0

Use curl’s --url option like this:

curl --upload-file /path/to/file/badname --url http://serverip/remotedir/goodname
2
  • This doesn't work
    – Yuval Adam
    Jun 27, 2018 at 7:42
  • This doesn't look like a general purpose solution
    – Yuri
    Apr 28, 2021 at 10:38
0

curl -v --user 'username:password' --upload-file {path}/{binaire} {your_url}/{binaire}

0

When you upload file using POST method and --form (-F) option, curl uses multipart/form-data content type:

POST /test.html HTTP/1.1
Host: example.org
Content-Type: multipart/form-data;boundary="boundary"

--boundary
Content-Disposition: form-data; name="field1"

value1
--boundary
Content-Disposition: form-data; name="field2"; filename="example.txt"

value2
--boundary--

As you can see, there is a place for filename. But when you use --upload-file (-T), curl will use PUT method and there will not be such place, because the body of the request will consist only of sole file body:

PUT /test.html HTTP/1.1
Host: example.org

file content

The only filename here is in URL itself: test.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.