Upload multiple file with vue js and axios Upload multiple file with vue js and axios laravel laravel

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.


If anyone wondering, "How can I send also data with it", there you go:

formData.append('name[' + this.name + ']', name);formData.getAll('files', 'name');