0

I'm trying to convert png file, produced by https://html2canvas.hertzen.com/ to a blob file, that I'd send to API.

Code below produces such output that API does not throw 400, however the file is somehow corrupted.

Is there something wrong with the way I construct the blob?

  const data = new FormData();
  const [, binary] = image.toDataURL().split(',');
  const blobFile = new Blob([window.atob(binary)], { type: 'image/png' });
  data.append('attachments[]', blobFile, 'screenshot.png');
Albert Nemec
  • 781
  • 2
  • 9
  • 13

1 Answers1

0

Alright, turns out canvas is already well equipped for translating itself to blob. All you have to do is use canvas.toBlob(cb) and you are ready to go.

Albert Nemec
  • 781
  • 2
  • 9
  • 13