Tôi hy vọng điều này sẽ hữu ích. Bằng cách tải ảnh lên FB chỉ với sự trợ giúp của javascript, bạn có thể sử dụng phương pháp sau. Điều bắt buộc ở đây là imageData (là định dạng hình ảnh base64) và loại mime.
try{
blob = dataURItoBlob(imageData,mimeType);
}catch(e){console.log(e);}
var fd = new FormData();
fd.append("access_token",accessToken);
fd.append("source", blob);fd.append("message","Kiss");
try{
$.ajax({
url:"https://graph.facebook.com/" + <<userID received on getting user details>> + "/photos?access_token=" + <<user accessToken>>,
type:"POST"
data:fd,
processData:false,
contentType:false,
cache:false,
success:function(data){
console.log("success " + data);
},
error:function(shr,status,data){
console.log("error " + data + " Status " + shr.status);
},
complete:function(){
console.log("Ajax Complete");
}
});
}catch(e){console.log(e);}
function dataURItoBlob(dataURI,mime) {
// convert base64 to raw binary data held in a string
// doesn't handle URLEncoded DataURIs
var byteString = window.atob(dataURI);
// separate out the mime component
// write the bytes of the string to an ArrayBuffer
//var ab = new ArrayBuffer(byteString.length);
var ia = new Uint8Array(byteString.length);
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
// write the ArrayBuffer to a blob, and you're done
var blob = new Blob([ia], { type: mime });
return blob;
}
Vui lòng trả lời câu hỏi này, Mã này đang hoạt động cho url hình ảnh web không dành cho Hình ảnh thiết bị của tôi, Nếu tôi sử dụng hình thức multipart/form-data và thay vì duyệt phương thức media cho thiết bị Android. Trình duyệt Android không hỗ trợ loại đầu vào = "tệp". Tôi nên làm gì? –
Bạn có tìm thấy giải pháp nào không? – Brune