Note that there are some explanatory texts on larger screens.

plurals
  1. POUploading an image to Picasa from a Chrome Extension
    primarykey
    data
    text
    <p>I'm trying to upload an image to Picasa from a Google Chrome Extension and running into some trouble constructing the POST.</p> <p>This is the protocol google specifies for uploading an image to Picasa (<a href="http://code.google.com/apis/picasaweb/docs/2.0/developers_guide_protocol.html#PostPhotos">link</a>):</p> <pre><code>Content-Type: multipart/related; boundary="END_OF_PART" Content-Length: 423478347 MIME-version: 1.0 Media multipart posting --END_OF_PART Content-Type: application/atom+xml &lt;entry xmlns='http://www.w3.org/2005/Atom'&gt; &lt;title&gt;plz-to-love-realcat.jpg&lt;/title&gt; &lt;summary&gt;Real cat wants attention too.&lt;/summary&gt; &lt;category scheme="http://schemas.google.com/g/2005#kind" term="http://schemas.google.com/photos/2007#photo"/&gt; &lt;/entry&gt; --END_OF_PART Content-Type: image/jpeg ...binary image data... --END_OF_PART-- </code></pre> <p>And this is what I've cobbled together to attempt to do that, borrowing code from <a href="http://code.google.com/p/grecipes/source/browse/js/gdocs.js">here</a> and the extension "clip-it-good":</p> <pre><code>function handleMenuClick(albumName, albumId, data, tab) { chrome.pageAction.setTitle({ tabId: tab.id, title: 'Uploading (' + data.srcUrl.substr(0, 100) + ')' }); chrome.pageAction.show(tab.id); var img = document.createElement('img'); img.onload = function() { var canvas = document.createElement('canvas'); canvas.width = img.width; canvas.height = img.height; canvas.getContext('2d').drawImage(img, 0, 0); var dataUrl = canvas.toDataURL(); var dataUrlAdjusted = dataUrl.replace('data:image/png;base64,', ''); var builder = new WebKitBlobBuilder(); builder.append(Base64.decode(dataUrlAdjusted).buffer); function complete(resp, xhr) { chrome.pageAction.hide(tab.id); if (!(xhr.status &gt;= 200 &amp;&amp; xhr.status &lt;= 299)) { alert('Error: Response status = ' + xhr.status + ', response body = "' + xhr.responseText + '"'); } } // end complete OAUTH.authorize(function() { OAUTH.sendSignedRequest( 'http://picasaweb.google.com/data/feed/api/' + 'user/default/albumid/' + albumId, complete, { method: 'POST', headers: { 'Content-Type': 'multipart/related; boundary=END_OF_PART', 'MIME-version': '1.0' }, parameters: { alt: 'json' }, body: constructContentBody_('title.jpg', 'photo', builder.getBlob('image/png'), 'image/jpeg', 'lolz') } ); }); } // end onload img.src = data.srcUrl; } function constructAtomXml_(docTitle, docType, docSummary) { var atom = ['&lt;entry xmlns="http://www.w3.org/2005/Atom"&gt;', '&lt;title&gt;', docTitle, '&lt;/title&gt;', '&lt;summary&gt;', docSummary, '&lt;/summary&gt;', '&lt;category scheme="http://schemas.google.com/g/2005#kind"', ' term="http://schemas.google.com/docs/2007#', docType, '"/&gt;', '&lt;/entry&gt;'].join(''); return atom; }; function constructContentBody_(title, docType, body, contentType, summary) { var body_ = ['--END_OF_PART\r\n', 'Content-Type: application/atom+xml;\r\n\r\n', constructAtomXml_(title, docType, summary), '\r\n', '--END_OF_PART\r\n', 'Content-Type: ', contentType, '\r\n\r\n', eval(body), '\r\n', '--END_OF_PART--\r\n'].join(''); return body_; }; </code></pre> <p>This returns "Error: Response status = 400, response body = "Invalid kind on entry.""</p> <p>I'm not sure if I'm doing something wrong with WebKitBlobBuilder or if my POST is improperly formed. Any suggestions would be welcome!</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.
 

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