access blob value outside of canvas.ToBlob() async function
const blob = await new Promise(resolve => canvasElem.toBlob(resolve));
You can use Promise
constructor, pass Blob
instance to resolve()
, access Promise
value at .then()
function getCanvasBlob(canvas) {
return new Promise(function(resolve, reject) {
canvas.toBlob(function(blob) {
resolve(blob)
})
})
}
var canvasBlob = getCanvasBlob(canvas);
canvasBlob.then(function(blob) {
// do stuff with blob
}, function(err) {
console.log(err)
});