I have to store some images, I'm taking the value like this:
var imgGaleria1 = $("#imgGaleria1")[0].files[0];
var imgGaleria1Blob;
if (imgGaleria1) {
var reader = new FileReader();
reader.onload = function (e) {
reader.readAsDataURL(imgGaleria1);
imgGaleria1Blob = e.target.result;
};
}
But obviously I can't store into imgGaleria1Blob
, because reader is just async
task, I searched that I need to do a promises that returns y value to store it, but I don't understand how promise works.
Can someone explain to me how can I execute this code into a promise and store the result (e.target.result
)?
Thanks for the help guys.