我需要为构造 2 插件编写一个 javascript 代码。下面是我的代码:
Acts.prototype.PublishToWallPHOTO = function (snapshotdata)
{
if (this.runtime.isDomFree || !fbLoggedIn)
return;
var blob;
try
{
blob = dataURItoBlob(snapshotdata.replace("data:image/png;base64,", ""),'image/png');
}
catch(e){console.log(e);}
FB.api('/me/photos', 'POST', {
message:'photo description',
source:blob
}, function(response) {
if (!response || response.error)
console.error(response);
});
};
function dataURItoBlob(dataURI,mime)
{
var byteString = window.atob(dataURI);
var ia = new Uint8Array(byteString.length);
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}
var blob = new Blob([ia], { type: mime });
return blob;
}
对于“snapshotdata”的上述代码参数,如下所示:“data:image/png;base64,iVBORw0KGgoAAAA.......”
但是我的图片没有使用上面的代码上传到 facebook。但如果我使用相同的代码url:'http://example.com/abc.png'
而不是 source:blob
它,它会成功上传给定 URL 中的图像。我试图找出上面代码的错误,但我找不到合适的解决方案。请告诉我是否有人知道上述代码的问题。
ps: 抱歉英语不好