The Google API I’m using is transmitting images only as binary data.
I have absolutly no idea how to put this into a data URI to display it, thanks for any help!
The call I’m talking about is this API call.
As you can see, it says:
The server returns bytes of the photo.
For the call (it’s an extension), I use the chrome_ex_oauth methods. Maybe I need to add something into the header to get real binary data, not string as it comes in right now…
What I need to do is to convert the resulting binary into data URI so I can display it.
Ok, I get this out of the XHR request

Now, I dont know binary stuff much. This is somehow encoded binary data i assume? I tried to put this into btoa and other base64 encoders, everything throws an error.
I tried to overrideMimeType with different things and the “response” changed in some strange ways, but nothing accepts the data.
So now I have this code:
var nxhr = new XMLHttpRequest();
nxhr.onreadystatechange = function (data) {
if (nxhr.readyState == 4) {
console.log(nxhr);
}
};
nxhr.open(method, url, true);
nxhr.setRequestHeader('GData-Version', '3.0');
nxhr.setRequestHeader('Authorization', oauth.getAuthorizationHeader(url, method, params));
nxhr.send('Data to send');
Anybody else has any idea how to get this for me not understandable response into a data uri???
Thanks for any help
Ok I found the solution…
First of all, the request must override the returend Type into x-user-defined
After that the data is untouched by the browser.
Use the following Base64 encoder
There is the magic stuff posted by mozilla which didnt let me encode the stuff correctly
The final code would look then like this…
P.S. If you put the “data:image/*” into the browser window directly, it will download the file and would not be able to open it. But if you put it directly into an img src it works fine!