Skip to content

Instantly share code, notes, and snippets.

@komatzz
Last active November 17, 2017 02:01
Show Gist options
  • Select an option

  • Save komatzz/6fd158eeac64e478baf1c7dfdc5880fe to your computer and use it in GitHub Desktop.

Select an option

Save komatzz/6fd158eeac64e478baf1c7dfdc5880fe to your computer and use it in GitHub Desktop.
Axios で multipart/form-data にした PUT リクエストが失敗する際の対策 ref: https://qiita.com/komatzz/items/21b58c92e14d2868ac8e
let formData = new FormData();
formData.append('picture', this.$refs.picture.files[0]);
let config = {
headers: {
'content-type': 'multipart/form-data',
},
};
window.axios.put('/api/test', formData, config)
.then((response) => {
// 成功時の処理
})
.catch((error) => {
// 失敗時の処理
});
let formData = new FormData();
formData.append('picture', this.$refs.picture.files[0]);
let config = {
headers: {
'content-type': 'multipart/form-data',
},
};
// PUT で上書く
config.headers['X-HTTP-Method-Override'] = 'PUT';
window.axios.post('/api/test', formData, config)
.then((response) => {
// 成功時の処理
})
.catch((error) => {
// 失敗時の処理
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment