I have this code to upload images to firebase storage, but because I have problem if I upload the same file with the same name, I want every image to have unique names like image-v432bn4bn324nm.png
How I can do that ?? With functions ?? if (YES){ return How?? }
addProsfora(prosfora, img) {
// let aa = this.checkIfImageExist(img, 'prosfores');
// console.log(aa);
function onAfterAddingFile(img) {
var fileExtension = '.' + img.name.split('.').pop();
img.name = Math.random().toString(36).substring(7) + new Date().getTime() + fileExtension;
console.log(img.name);
};
onAfterAddingFile(img);
const storageRef = firebase.storage().ref();
console.log(img);
let path = `/${this.prosforesFolder}/${img.name}`;
let iRef = storageRef.child(path);
iRef.put(img).then((snapshot) => {
prosfora.imageUrl = snapshot.downloadURL;
prosfora.image = img.name;
prosfora.path = path;
// firebase.database().ref('/listings').push(listing);
return this.prosfores.push(prosfora);
});
}