Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6979865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:56:25+00:00 2026-05-27T17:56:25+00:00

The Google API I’m using is transmitting images only as binary data. I have

  • 0

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

enter image description here

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:56:26+00:00Added an answer on May 27, 2026 at 5:56 pm

    Ok I found the solution…

    First of all, the request must override the returend Type into x-user-defined

    xhr.overrideMimeType('text\/plain; charset=x-user-defined');
    

    After that the data is untouched by the browser.

    Use the following Base64 encoder

    Base64 = {
    
                // private property
                _keyStr: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
    
                encodeBinary: function (input) {
                    var output = "";
                    var bytebuffer;
                    var encodedCharIndexes = new Array(4);
                    var inx = 0;
                    var paddingBytes = 0;
    
                    while (inx < input.length) {
                        // Fill byte buffer array
                        bytebuffer = new Array(3);
                        for (jnx = 0; jnx < bytebuffer.length; jnx++)
                            if (inx < input.length)
                                bytebuffer[jnx] = input.charCodeAt(inx++) & 0xff; // throw away high-order byte, as documented at: https://developer.mozilla.org/En/Using_XMLHttpRequest#Handling_binary_data
                            else
                                bytebuffer[jnx] = 0;
    
                        // Get each encoded character, 6 bits at a time
                        // index 1: first 6 bits
                        encodedCharIndexes[0] = bytebuffer[0] >> 2;
                        // index 2: second 6 bits (2 least significant bits from input byte 1 + 4 most significant bits from byte 2)
                        encodedCharIndexes[1] = ((bytebuffer[0] & 0x3) << 4) | (bytebuffer[1] >> 4);
                        // index 3: third 6 bits (4 least significant bits from input byte 2 + 2 most significant bits from byte 3)
                        encodedCharIndexes[2] = ((bytebuffer[1] & 0x0f) << 2) | (bytebuffer[2] >> 6);
                        // index 3: forth 6 bits (6 least significant bits from input byte 3)
                        encodedCharIndexes[3] = bytebuffer[2] & 0x3f;
    
                        // Determine whether padding happened, and adjust accordingly
                        paddingBytes = inx - (input.length - 1);
                        switch (paddingBytes) {
                            case 2:
                                // Set last 2 characters to padding char
                                encodedCharIndexes[3] = 64;
                                encodedCharIndexes[2] = 64;
                                break;
                            case 1:
                                // Set last character to padding char
                                encodedCharIndexes[3] = 64;
                                break;
                            default:
                                break; // No padding - proceed
                        }
                        // Now we will grab each appropriate character out of our keystring
                        // based on our index array and append it to the output string
                        for (jnx = 0; jnx < encodedCharIndexes.length; jnx++)
                            output += this._keyStr.charAt(encodedCharIndexes[jnx]);
                    }
                    return output;
                }
            };
    

    There is the magic stuff posted by mozilla which didnt let me encode the stuff correctly

    bytebuffer[jnx] = input.charCodeAt(inx++) & 0xff
    

    The final code would look then like this…

    oauth.authorize(function () {
        var method = "GET", params = {}, url = photo.href;
    
        var nxhr = new XMLHttpRequest();
        nxhr.onreadystatechange = function (data) {
            if (nxhr.readyState == 4) {
                console.log("<img src='data:image/*;base64," + Base64.encodeBinary(nxhr.response) + "' />");
            }
        };
        nxhr.open(method, url, true);
        nxhr.setRequestHeader('GData-Version', '3.0');
        nxhr.setRequestHeader('Authorization', oauth.getAuthorizationHeader(url, method, params));
        nxhr.overrideMimeType('text\/plain; charset=x-user-defined'); 
    });
    

    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!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the Google API to get a user's location on this site .
The Google Finance API only have Java / Javascript. Is there any ideas on
I'm using Google Translate API, and if I try to translate Mc Donald's this
I'm using a Google API to return some JSON, which i have converted to
I have a Google API console premier account, and I'm using the places service
I am using Google API V3 and I want to have a ground overlay
Does anyone know the query limit for this undocumented/unofficial google api?
Tried this: $('.link').click(function(e) { $.getScript('http://www.google.com/uds/api?file=uds.js&amp;v=1.0', function() { $('body').append('<p>GOOGLE API (UDS) is loaded</p>'); }); return
Using the Google Maps API, how can I get the latitude and longitude of
The google API example shows that you should have the javascript within the head

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.