0
// get the file in Base64
function getBase64(file) {
    return new Promise((resolve, reject) => {
        const reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = () => resolve(reader.result);
        reader.onerror = error => reject(error);
    });
}



var storeInTheGlobalVariable = '';



var ImageBase64 = getBase64(bottomBannerImage).then(function(data){
    storeInTheGlobalVariable = data; // not woking -> undefine
    console.log(data) // working fine
});

I don't want to console log. I want the promise resolve data. How I will get It outside of this then() method

kundefine
  • 83
  • 10
  • 1
    The code that you'd like to access storeInTheGlobalVariable needs to be run after the variable is saved. If you guarantee that, then things will work as expected. Mind sharing what code you feel doesn't have access to this variable, but should have access to it? – ctt May 06 '19 at 12:18
  • Possible duplicate of [How to extract data out of a Promise](https://stackoverflow.com/questions/36911241/how-to-extract-data-out-of-a-promise) – Nick Parsons May 06 '19 at 12:19
  • How do you know that storeInTheGlobalVariable does not successfully store data? Can you explain exactly how did you test that? – Lajos Arpad May 06 '19 at 12:23

0 Answers0