-1
uploadImage(extraFileItems[i])
          .then(response => 
            console.log(response)


            );
            
            // addItemToBin(bin, name, url);

I'm calling a function here that fetches data from an API. The API returns a promise with a result of what I want to pass as the "URL" parameter in the "addItemToBin" function. How can I call the "addItemToBin" function and pass it an argument of the promise result in the uploadImage function call?

I tried taking the response and setting it to a variable called url, however, that doesn't work. I also tried just calling the "addItemToBin" function in the .then however, that doesn't work either.

  • 1
    Does this answer your question? [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – Simone Rossaini Nov 07 '22 at 19:20

1 Answers1

0

I also tried just calling the "addItemToBin" function in the .then however, that doesn't work either.

That's the way to do it.

uploadImage(extraFileItems[i])
  .then(response => addItemToBin(bin, name, response));

If that didn't work for you then please provide more details.

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143