LoginSignup
39

More than 5 years have passed since last update.

curlでファイルアップロードする方法と注意点

Last updated at Posted at 2014-11-28

以下のように-Fオプションを使った上(ファイルのところだけでなく、全パラメータ-F)、 @/path..でファイル指定するだけ。ラクラク。curl++

curl -X PUT http://hoge.com/path -F hoge=fuga -F foo=bar -F "file=@/path/to/file.ext;type=image/jpg"

ただし、以下を注意。

  • -d-Fを混在させない。混在するとWarning: You can only select one HTTP request! という謎エラーになる。
  • -Fのときは -dみたいに"hoge=fuga&foo=bar"とは書けない。おとなしくパラメータ一個ずつ書く。
  • content-typeを指定する。指定しないと application/octet-stream になる。そのときは""でくくるのを忘れずに。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
39