Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok I found the solution...</p> <h2>First of all, the request must override the returend Type into x-user-defined</h2> <pre><code>xhr.overrideMimeType('text\/plain; charset=x-user-defined'); </code></pre> <p>After that the data is untouched by the browser.</p> <h2>Use the following Base64 encoder</h2> <pre><code>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 &lt; input.length) { // Fill byte buffer array bytebuffer = new Array(3); for (jnx = 0; jnx &lt; bytebuffer.length; jnx++) if (inx &lt; input.length) bytebuffer[jnx] = input.charCodeAt(inx++) &amp; 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] &gt;&gt; 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] &amp; 0x3) &lt;&lt; 4) | (bytebuffer[1] &gt;&gt; 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] &amp; 0x0f) &lt;&lt; 2) | (bytebuffer[2] &gt;&gt; 6); // index 3: forth 6 bits (6 least significant bits from input byte 3) encodedCharIndexes[3] = bytebuffer[2] &amp; 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 &lt; encodedCharIndexes.length; jnx++) output += this._keyStr.charAt(encodedCharIndexes[jnx]); } return output; } }; </code></pre> <p>There is the magic stuff posted by mozilla which didnt let me encode the stuff correctly</p> <pre><code>bytebuffer[jnx] = input.charCodeAt(inx++) &amp; 0xff </code></pre> <p>The final code would look then like this...</p> <pre><code>oauth.authorize(function () { var method = "GET", params = {}, url = photo.href; var nxhr = new XMLHttpRequest(); nxhr.onreadystatechange = function (data) { if (nxhr.readyState == 4) { console.log("&lt;img src='data:image/*;base64," + Base64.encodeBinary(nxhr.response) + "' /&gt;"); } }; 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'); }); </code></pre> <p>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!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload