I'm trying to upload multiple photos to my Firebase Storage. For some reason it keeps overwriting the original upload, and it's not creating the folder with the venueID property. Can anybody shine a light here?
main.ts
async localPictureUpload(): Promise<any> {
// Checks if there is something to be uploaded.
if (this.photosToUpload.length > 0) {
const location = `venues/photos/${this.venueID}/`;
// photosToUpload is an array containing base64 strings.
this.photosToUpload.forEach(async photoElement => {
const randomID = this.venueService.createID();
await this.uploadService.uploadFile(photoElement, location, true)
.then(async data => {
const urlData = await data.ref.getDownloadURL();
const photoObject: Photo = {
fileName: `${this.venueID}${randomID}`,
url: urlData,
uploadedBy: this.currentUserID
};
await this.venueService.addPhoto(this.venueID, photoObject);
},
(err) => console.error(err));
});
} else {
return;
}
}
upload.service
uploadFile(file: any, path: string, base64?: boolean) {
if (base64) {
return this.uploadDB.ref(path).putString(file, 'data_url');
} else {
return this.uploadDB.upload(path, file);
}
}
console.log(path);right beforethis.uploadDB.ref(path).putString(file, 'data_url')and showing the output? 2) Replacing the complex code with a simpler hard-coded path with/in it, to see if that works. After doing these, please edit your question to show the updated (hopefully simpler) result and output.venues/photos/0WiFtVRvPj63GlEAqsEF/that seems ok right? In theory the last part should be the folder (which has the record id) and the file should be added right after, correct?