This might come later than you needed it, however it might still help people that will be looking for this.
First off, use axios library to send your files from your frontend to your backend.
Make sure you use FormData on Javascript side.
Here is a piece of code that will help you process your upload and send it to the server.
< input type = "file"
multiple = "multiple"
id = "attachments"
@change = "uploadFieldChange" >
// This function will be called every time you add a file
uploadFieldChange(e) {
var files = e.target.files || e.dataTransfer.files;
if (!files.length)
return;
for (var i = files.length - 1; i >= 0; i--) {
this.attachments.push(files[i]);
}
// Reset the form to avoid copying these files multiple times into this.attachments
document.getElementById("attachments").value = [];
}
submit() {
this.prepareFields();
var config = {
headers: {
'Content-Type': 'multipart/form-data'
},
onUploadProgress: function (progressEvent) {
this.percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total);
this.$forceUpdate();
}.bind(this)
};
// Make HTTP request to store announcement
axios.post(this.settings.file_management.upload_files, this.data, config)
.then(function (response) {
console.log(response);
if (response.data.success) {
console.log('Successfull Upload');
toastr.success('Files Uploaded!', 'Success');
this.resetData();
} else {
console.log('Unsuccessful Upload');
this.errors = response.data.errors;
}
}.bind(this)) // Make sure we bind Vue Component object to this funtion so we get a handle of it in order to call its other methods
.catch(function (error) {
console.log(error);
});
}
Complete solution has a few more lines of code and is wrapped in a Laravel project.
You can find more details on Medium:
https://medium.com/@adnanxteam/how-to-upload-multiple-files-via-ajax-vuejs-and-laravel-5-5-file-management-d218c3bbb71c