title: Trying send upload image to image server on button click , then return url and store to the backend. How to do it sequentially
body: <p>this is the image upload code the URL only returns after the form has been submitted to the backend. Trying send upload image to an image server on button click, then return URL and store to the backend. How to do it sequentially</p>
  <pre><code>    const handleImgUpload = async imgb =&gt; {
   
      try {
    const images = imgb;
    let promiseArray = [];
    let imgbb = images.toString('base64');
    const details = {image: `${imgbb}`};
    let formBody = [];
    for (const property in details) {
      const encodedKey = encodeURIComponent(property);
      const encodedValue = encodeURIComponent(details[property]);
      formBody.push(encodedKey + '=' + encodedValue);
    }
    formBody = formBody.join('&amp;');
    promiseArray.push(
      fetch(
        'https://api.imgbb.com/1/upload?key=xxxxxxxxxxxx',
        {
          method: 'POST',
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
          },
          body: formBody,
        },
      ).then(r =&gt; r.json()),
    );
  
    Promise.all(promiseArray)
      .then(values =&gt; {
        if (values[0].success) {
          let thumb = '';
          values.map(imgs =&gt; {
            thumb = values[0].data.thumb.url;
            setImgUrl(imgs.data.url.replace(/[&quot;']/g, ''));
          });
          // setImageLoader(false);
          //YOU SEND imgURL
          // handleSubmitButton();
        } else {
          // setImageLoader(false);
          alert(
            'An error occurred while uploading image, please check your connection and try again',
          );
        }
      })
      .catch(err =&gt; {
        // setImageLoader(false);
        console.log('ERORRRRR', err);
        alert(err);
      });
  } catch (e) {
    // setImageLoader(false);
    console.log('ERRRR', e);
  }
  </code></pre>
  <p>};</p>
  <p>this is the submit button code
  I want to fetch the return URL first and then store it to a state then upload it to backend**</p>
  <pre><code> const handleSubmitButton = async () =&gt; {
  
  
  handleImgUpload(img); **handle upload function**
  
  // Show Loader
  setLoading(true);
  
  UserApi.ElectionReport({
  
    imgUrl,
   
  })
    .then(function (response) {
      // response handling
      setValue(response);
      console.log('res', response.data);
  
      if (response.data == 'successful') {
        // console.log('res', response.data)
        navigation.navigate('Home');
  
        alert('Sent Successfully');
        return;
      }
      setLoading(false);
      console.log('res', response.data);
    })
    .catch(function (error) {
      // error handling
      if (error.response) {
        alert(error.message);
        setLoading(false);
      }
    });
  </code></pre>
  <p>};</p>