0

In this piece of code, I'd like to alert the "resizedImageToUpload" variable from within the if(pickedImagePath != "") statement.

The alert within the resizeImage = async () function works fine, the one within the if(pickedImagePath != "") returns undefined.

  var resizedImageToUpload;

  const resizeImage = async () => {
    const manipResult = await manipulateAsync(
      pickedImagePath,
      [
        { resize: { width: 390 }},
      ],
      { compress: 1, format: SaveFormat.PNG }
    );

    var manipResultSTR = JSON.stringify(manipResult);
    var manipResultPARSED = JSON.parse(manipResultSTR);
    var resizedImageToUpload = manipResultPARSED.uri;
    alert("resizedImageToUpload IS: "+resizedImageToUpload);
  };

  if(pickedImagePath != ""){
    resizeImage();
    alert("resizedImageToUpload IS: "+resizedImageToUpload);
  }

I guess it's because of the async function not being called yet by the time the "if(...)" is triggered.

gigapico00
  • 417
  • 1
  • 7
  • 24

0 Answers0