My goal is to upload multiple files from a Vue.js frontend to a php/Laravel backend.
This is where I collect the files:
<input id="cover-file" @change="onCoverSelected" type="file" multiple>
This is the onCoverSelected
method:
onCoverSelected(e) {
let files = e.target.files;
// let fileArray = Object.values(files);
for (var i = 0; i < files.length; i++) {
console.log(files[1]);
this.covers.push(files[1]);
}
},
When I console.log
the files, they appear as actual files in the DevTools console. So far so good.
However, when I push the files to an array, they become strings! I don't understand why. My backend depends on receiving an array of file objects.
This is a screenshot from DevTools where it shows that the File object becomes a string
This is from my backend where I hope to receive an array of File objects, however, I receive an empty array when I dd
the covers
variable:
$covers = (array)json_decode($request->input('covers'));
dd($covers);
not using the (array)
prints the below:
"[object File],[object File],[object File]"
How can I receive an array of File
objects in the backend? Thank you.