Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

187
Visualizações
Accesing the promise return value inside another function

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 using await 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!

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda