LoginSignup
0
1

More than 5 years have passed since last update.

fetchコマンドでファイルをアップロードしたい

Posted at

はじめに

タイトル通りです。
今更書くことかな?とも思うんですが、人に教えることもたまにあるので、このページ見てーで済ませるためにも一応。

fetch

upload.js
// 変数fileにinput type=fileの結果でもなんでも用意しておく

const formData = new FormData();
formData.append('file', file);

fetch('/upload_saki_no_url', {
  method: 'post',
  body: formData,
})
.then(res => res.text())
.then(text => console.log(text));

後はサーバ側の処理と異常系の処理を煮るなり焼くなり好きに書く感じで!
それにしてもfetchコマンドは便利だなぁ。

0
1
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
0
1