title: Uploading file to wordpress via xml-rpc and javascript
body: <p>I am trying to write a chrome extension that can upload a picture to a wordpress blog. So far, so good, however the wordpress rpc api is expecting the picture in binary: </p>
  
  <p><a href="http://codex.wordpress.org/XML-RPC_WordPress_API/Media#wp.uploadFile" rel="nofollow">http://codex.wordpress.org/XML-RPC_WordPress_API/Media#wp.uploadFile</a></p>
  
  <p>Unfortunately, the data I have is base64 encoded</p>
  
  <p><a href="http://developer.chrome.com/extensions/tabs.html#method-captureVisibleTab" rel="nofollow">http://developer.chrome.com/extensions/tabs.html#method-captureVisibleTab</a></p>
  
  <p>When firing my code, the only feedback I get from Wordpress is: <code>faultCode -32700, parse error. not well formed</code></p>
  
  <p>This is it:</p>
  
  <pre><code>chrome.tabs.captureVisibleTab(null, {"format": "png"}, function(img) {
  
      var data = new Object();
      data.name = 'Screenshot' + Math.floor(Math.random() * 100); //pageTitle 
      data.overwrite = false;
      data.type = 'image/png'; //string:File MIME type.
  
      //transfrom screencapture into binary data for wordpress xmlrpc
      var regex = /^data:.+\/(.+);base64,(.*)$/;
      var matches = img.match(regex);
      data.bits = atob(matches[2]); //string: binary data. Shouldn't be base64-encoded.
  
      $.xmlrpc({
          url: wp.url,
          methodName: 'wp.uploadFile',
          params: [0, wp.user, wp.password, data],
          success: function(response, status, jqXHR) { 
              //this return the post id
              alert("worked :-)" + status + "/" + response + "/" +
                    jqXHR.responseXML + "/" + response.url); 
          },
          error: function(jqXHR, status, error) { 
              alert("fail :-(" + status + " " + error + " " + jqXHR.responseXML); 
          }
      });
  });
  </code></pre>
  
  <p>Do you have any idea how I could get this working? Thanks a million!</p>