I have a following function that uploads an image:
const uploadImage = async () => {
const storageRef = ref(storage, `${user.uid}/${imageName}`);
uploadBytes(storageRef, image).then((snapshot) => {
console.log("Uploaded a blob or file!");
getDownloadURL(snapshot.ref).then((downloadURL) => {
console.log("File available at", downloadURL);
return downloadURL;
});
});};
I want to access the returning value from it inside another function, but it just returns undefined:
const anotherFunc = () => {
console.log(uploadImage()) // I want it to log the value of downloadURL, but instead it logs "undefined"
What I've tried:
- making
anotherFunc
async and tried accesing value usingawait uploadImage
- accesing value using
.then()
Per my understanding, the function uploadImage
returns a promise, because it's an async function. I guess I'm trying to access the value before the promise resolves? But still it doesnt work even with await. Can't quite wrap my head around promises yet. Any help is very appreciated, thanks in advance!