45
43

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

axios で ファイルをPOSTする

Last updated at Posted at 2017-06-08

axios で ファイルを POST する

Ajax で ファイルをポストしたい

Ajax を使って multipart/form-data ファイルをポストしたい場合のやり方はこちら

  • HTML
<input type="file" name="file">
  • Javascript
var params = new FormData();
var fileSelectDom = $('[name=\`file\`]')[0];

params.append('file', fileSelectDom.files[0]);
axios.post(url, params)
      .then(function(response) {
        // 成功時
      })
      .catch(function(error) {
        // エラー時
      });

これで後はサーバサイドで、普通にFormからPostされたように受ければOK

45
43
0

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
45
43

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?