Skip to content

Instantly share code, notes, and snippets.

@andyburke
andyburke / facebook-photo-post-javascript.js
Created December 19, 2011 20:37
How to post a photo to Facebook from client-side Javascript
// This bit is important. It detects/adds XMLHttpRequest.sendAsBinary. Without this
// you cannot send image data as part of a multipart/form-data encoded request from
// Javascript. This implementation depends on Uint8Array, so if the browser doesn't
// support either XMLHttpRequest.sendAsBinary or Uint8Array, then you will need to
// find yet another way to implement this. (This is left as an exercise for the reader,
// but if you do it, please let me know and I'll integrate it.)
// from: http://stackoverflow.com/a/5303242/945521
if ( XMLHttpRequest.prototype.sendAsBinary === undefined ) {
function fitStringToSize(str,len) {
var result = str;
var span = document.createElement("span");
span.style.visibility = 'hidden';
span.style.padding = '0px';
document.body.appendChild(span);
// on first run, check if string fits into the length already.
span.innerHTML = result;
if(span.offsetWidth > len) {