Skip to content

Instantly share code, notes, and snippets.

@artlili
Created May 26, 2019 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artlili/2bc158b8cdc97c8206e52e2374283f2d to your computer and use it in GitHub Desktop.
Save artlili/2bc158b8cdc97c8206e52e2374283f2d to your computer and use it in GitHub Desktop.
Axios upload multiple files
<input type="file" ref="file" multiple="multiple">
submitFiles() {
let formData = new FormData();
for( var i = 0; i < this.$refs.file.files.length; i++ ){
let file = this.$refs.file.files[i];
console.log(file);
formData.append('files[' + i + ']', file);
}
axios.post( '/fileupload', formData, {
headers: {
'Content-Type': 'multipart/form-data'
},
}
).then(function(){
})
.catch(function(){
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment