Search code examples
curlfile-uploadstdin

Upload data from stdin as a file with a specific name via cURL


I'm using curl -F file=@- http://etc/upload to upload some data I'm piping into cURL, and that's working fine, but I'd like to be able to specify the file name that's reported to the server.

Is that possible? How?


Solution

  • From the cURL man page:

    -F/--form <name=content>

    ...

    You can [...] explicitly change the name field of an file upload part by setting filename=, like this:

    curl -F "file=@localfile;filename=nameinpost"

    So this is exactly what I wanted. E.g.:

    echo funfunfun | curl -F file=@-;filename=fun.txt http://etc/upload
    

    I swear I had read the man pages a couple times before asking, but hadn't found that particular paragraph until now.