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 7774593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:25:05+00:00 2026-06-01T17:25:05+00:00

I’m trying to POST an image (with Metadata) to Picasa Webalbums from within a

  • 0

I’m trying to POST an image (with Metadata) to Picasa Webalbums from within a Chrome-Extension. Note that a regular post with Content-Type image/xyz works, as I described here. However, I wish to include a description/keywords and the protocol specification describes a multipart/related format with a XML and data part.

I’m getting the Data through HTML5 FileReader and user file input. I retrieve a binary
String using

FileReader.readAsBinaryString(file);

Assume this is my callback code once the FileReader has loaded the string:

function upload_to_album(binaryString, filetype, albumid) {

    var method = 'POST';
    var url = 'http://picasaweb.google.com/data/feed/api/user/default/albumid/' + albumid;
    var request = gen_multipart('Title', 'Description', binaryString, filetype);
    var xhr = new XMLHttpRequest();
    xhr.open(method, url, true);
    xhr.setRequestHeader("GData-Version", '3.0');
    xhr.setRequestHeader("Content-Type",  'multipart/related; boundary="END_OF_PART"');
    xhr.setRequestHeader("MIME-version", "1.0");
    // Add OAuth Token
    xhr.setRequestHeader("Authorization", oauth.getAuthorizationHeader(url, method, ''));
    xhr.onreadystatechange = function(data) {
        if (xhr.readyState == 4) {
            // .. handle response
        }
    };
    xhr.send(request);
}   

The gen_multipart function just generates the multipart from the input values and the XML template and produces the exact same output as the specification (apart from ..binary image data..), but for sake of completeness, here it is:

function gen_multipart(title, description, image, mimetype) {
    var multipart = ['Media multipart posting', "   \n", '--END_OF_PART', "\n",
    'Content-Type: application/atom+xml',"\n","\n",
    "<entry xmlns='http://www.w3.org/2005/Atom'>", '<title>', title, '</title>',
    '<summary>', description, '</summary>',
    '<category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/photos/2007#photo" />',
    '</entry>', "\n", '--END_OF_PART', "\n",
    'Content-Type:', mimetype, "\n\n",
    image, "\n", '--END_OF_PART--'];
    return multipart.join("");
}

The problem is, that the POST payload differs from the raw image data, and thus leads to a Bad Request (Picasa won’t accept the image), although it worked fine when using

xhr.send(file) // With content-type set to file.type

My question is, how do I get the real binary image to include it in the multipart? I assume it is mangled by just appending it to the xml string, but I can’t seem to get it fixed.

Note that due to an old bug in Picasa, base64 is not the solution.

  • 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-06-01T17:25:06+00:00Added an answer on June 1, 2026 at 5:25 pm

    The XMLHttpRequest specification states that the data send using the .send() method is converted to unicode, and encoded as UTF-8.

    The recommended way to upload binary data is through FormData API. However, since you’re not just uploading a file, but wrapping the binary data within XML, this option is not useful.

    The solution can be found in the source code of the FormData for Web Workers Polyfill, which I’ve written when I encountered a similar problem. To prevent the Unicode-conversion, all data is added to an array, and finally transmitted as an ArrayBuffer. The byte sequences are not touched on transmission, per specification.

    The code below is a specific derivative, based on the FormData for Web Workers Polyfill:

    function gen_multipart(title, description, image, mimetype) {
        var multipart = [ "..." ].join(''); // See question for the source
        var uint8array = new Uint8Array(multipart.length);
        for (var i=0; i<multipart.length; i++) {
            uint8array[i] = multipart.charCodeAt(i) & 0xff;
        }
        return uint8array.buffer; // <-- This is an ArrayBuffer object!
    }
    

    The script becomes more efficient when you use .readAsArrayBuffer instead of .readAsBinaryString:

    function gen_multipart(title, description, image, mimetype) {
        image = new Uint8Array(image); // Wrap in view to get data
    
        var before = ['Media ... ', 'Content-Type:', mimetype, "\n\n"].join('');
        var after = '\n--END_OF_PART--';
        var size = before.length + image.byteLength + after.length;
        var uint8array = new Uint8Array(size);
        var i = 0;
    
        // Append the string.
        for (; i<before.length; i++) {
            uint8array[i] = before.charCodeAt(i) & 0xff;
        }
    
        // Append the binary data.
        for (var j=0; j<image.byteLength; i++, j++) {
            uint8array[i] = image[j];
        }
    
        // Append the remaining string
        for (var j=0; j<after.length; i++, j++) {
            uint8array[i] = after.charCodeAt(j) & 0xff;
        }
        return uint8array.buffer; // <-- This is an ArrayBuffer object!
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

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.