I am currently facing an issue with uploading multiple images to a real-time Firebase database. I have successfully managed to upload one image, but I am unsure how to handle multiple images at once.
This is the code snippet for uploading a single image:
<v-layout row>
<v-flex xs12 sm6 offset-sm3>
<!-- Using 'accept' attribute to only allow image files -->
<v-btn raised @click="onPickFile">Upload image</v-btn>
<input
type="file"
style="display:none"
ref="fileInput"
accept="image/*"
@change="onFilePicked"/></v-flex
></v-layout>
In my data object, I have two properties: imgURL: "", image: null. The following method handles the file selection:
onFilePicked(event) {
const files = event.target.files;
let filename = files[0].name;
if (filename.lastIndexOf(".") <= 0) {
return alert("Please add a valid file!");
}
const fileReader = new FileReader();
fileReader.addEventListener("load", () => {
this.imgURL = fileReader.result;
});
fileReader.readAsDataURL(files[0]);
this.image = files[0];
},