Upload multiple file with vue js and axios
You forgot to use $refs
. Add ref
to your input:
<input type="file" ref="file" multiple="multiple">
Next, access your files like this:
submitFiles() { let formData = new FormData(); for( var i = 0; i < this.$refs.file.files.length; i++ ){ let file = this.$refs.file.files[i]; formData.append('files[' + i + ']', file); } axios.post('/fileupload', formData, { headers: { 'Content-Type': 'multipart/form-data' }, } ).then(function(){ }) .catch(function(){ });},
This should be works.