get a download URL of a file
// or photoRef
getDownloadURL(uploadTask.snapshot.ref)
.then((url) => {
const img = document.querySelector('.file');
img.setAttribute('src', url);
})
.catch((error) => {
switch (error.code) {
case 'storage/object-not-found':
// File doesn't exist
break;
case 'storage/unauthorized':
// User doesn't have permission to access the object
break;
case 'storage/canceled':
// User canceled the upload
break;
case 'storage/unknown':
// Unknown error occurred, inspect the server response
break;
}
});
const deleteFileForm = document.querySelector(".deleteFile")
deleteFileForm.addEventListener('submit', e => {
e.preventDefault()
const fileRef = ref(storage, deleteFileForm.file.value)
deleteObject(fileRef)
.then(() => {
deleteBookForm.reset()
console.log("delete file sucessfully")
})
.catch((err) => {
console.error(err.message)
})
})