I'm trying to write a program that dowloads OneNote pages to my pc, including files in the pages. I'm stuck on the downloading images from the pages. I make a GET request and get the binary data for the image just fine, when I save it and try to open it, I get a "it looks like we don't support this file format. The code I'm using is
var u16 = btoa(unescape(encodeURIComponent(resp)));
var imgAsBlob = new Blob([u16], {type: 'application/octet-stream'});
var downloadLink = document.createElement("a");
downloadLink.download = "hello.png";
downloadLink.href = window.webkitURL.createObjectURL(imgAsBlob);
downloadLink.click();
resp
is the responseText from the GET request with the binary data.
I've tried not using btoa
and saving the resp directly on the blob. I've tried changing the blob type to image/png
and I've tried escaping it using Uint16Array(resp.length)
and equaling each byte to a byte from resp. I'm out of ideas and don't know what I'm doing wrong.