Skip to content Skip to sidebar Skip to footer

Post Binary Data Cross Domain In Javascript

I'm writing a Chrome browser extension that takes a snapshot of the current tab's view and uploads it to a web service API that I don't control. The Chrome extension library has a

Solution 1:

Turns out that you can do this.

Chrome has a way to send a blob via XMLHTTPRequest.

Here's a link to example code from the Chromium issue tracker:

http://code.google.com/p/chromium/issues/detail?id=35705#c34

XMLHttpRequest.prototype.sendAsBinary = function(datastr,contentType) {
    var bb = newBlobBuilder();
    var len = datastr.length;
    var data = newUint8Array(len);
    for (var i=0; i<len; i++) {
            data[i] = datastr.charCodeAt(i);
    }
    bb.append(data.buffer);
    this.send(bb.getBlob(contentType));
}

Post a Comment for "Post Binary Data Cross Domain In Javascript"