通过 cURL 从 stdin 将数据上传为具有特定名称的文件

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

我正在使用 curl -F file=@- http://etc/upload 上传一些我通过管道传输到 cURL 的数据,这工作正常,但我希望能够指定报告给服务器的文件名。

这可能吗?怎么样?

来自 cURL 手册页:

-F/--form

...

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

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

这正是我想要的。例如:

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

我发誓在提问之前我已经阅读了几次手册页,但直到现在才找到那个特定的段落。

对于 HTTP 以外的协议,要将 PUT 用于 HTTP 而不是表单提交,请使用 -T - 和 URL 中的文件名:

echo bla-bla-bla | curl -T - ftp://user:password@example.com/foo.txt