Closed pmourelle closed 5 years ago
@pmourelle I think you miss await
to val = myImageCompressor(val, maxMB, maxSize);
Async/await works for me
@pmourelle @kdalkafoukis is right, your async function "myImageCompressor " return a promise which needs to be "await" for the result.
You may try:
Promise.all(Object.entries(payload).map(async (item) => {
let [key, val] = item;
...
const maxMB = 1, // max MBs
maxSize = 1200; // max Size rescale
val = await myImageCompressor(val, maxMB, maxSize);
//or just: val = await imageCompressor(val, maxMB, maxSize);
...
})).then(successFn).catch(errorHandlerFn)
Thanks guys. I'd done some workaround on overall code. I'll try some clean up on this next week.
Hi there. I'm trying to use browser-image-compression with async/await, not being able to do it. I wrapped the call to have it resolve by its own and having a cleaner code as below (showing relevant parts).
Then I'm using it as:
Problem is that
val
doesn't have a File but a still unsolved Promise. Is this a bug or there's anything wrong in the code above?