Last active
November 17, 2017 02:01
-
-
Save komatzz/6fd158eeac64e478baf1c7dfdc5880fe to your computer and use it in GitHub Desktop.
Axios で multipart/form-data にした PUT リクエストが失敗する際の対策 ref: https://qiita.com/komatzz/items/21b58c92e14d2868ac8e
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) => { | |
| // 失敗時の処理 | |
| }); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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