Using HTML5 File API to upload Photos via Facebook Graph API
I'm trying to make a photo organizing Facebook application without using server-side process.
Now I can preview photos by using FileReader object's readAsDataURL method, such as...
var file = e.dataTransfer.files[0];
var reader = new FileReader();
reader.onload = function(e) {
var imgObj = $(document.createElement('img')).attr('src',reader.result).appendTo('#image_preview_wrapper');
};
reader.readAsDataURL(file);
}, false);
The question is how to post the image data to Facebook. I'm trying to do something like
var reader = new FileReader();
reader.onload = function(e) {
var data = reader.result;
FB.api('/me/photos','post',{ image : data },funct开发者_如何学运维ion(res){
alert(res);
});
}
reader.readAsBinaryString(file);
In this case, I can't set enctype="multipart/form-data" and I'm getting 400 Bad Request.
Can anybody help me?
精彩评论