我们将 BASE64 图像与状态消息一起发布到用户相册。一切正常,但如果状态消息包含非基本 ASCII 字符,则这些字符未正确编码。
我们尝试了:
var encodedPng = imageData.substring(imageData.indexOf(',')+1,imageData.length);
imageData = Base64Binary.decode(encodedPng);
// this is the multipart/form-data boundary we'll use
var boundary = '----ThisIsTheBoundary1234567890';
// let's encode our image file, which is contained in the var
var formData = '--' + boundary + '\r\n'
formData += 'Content-Disposition: form-data; name="source"; filename="' + filename + '"\r\n';
formData += 'Content-Type: ' + mimeType + '\r\n\r\n';
for ( var i = 0; i < imageData.length; ++i )
formData += String.fromCharCode( imageData[ i ] & 0xff );
formData += '\r\n';
formData += '--' + boundary + '\r\n';
formData += 'Content-Disposition: form-data; name="message"\r\n';
formData += 'Content-Type: text/html; charset=utf-8\r\n\r\n';
formData += message + "\r\n"
formData += '--' + boundary + '--\r\n';
var xhr = new XMLHttpRequest();
xhr.open( 'POST', 'https://graph.facebook.com/'+picMood.fb_album_id+'/photos?access_token=' + token, true );
xhr.onload = xhr.onerror = function() {
if(typeof callback == "function")
callback();
};
xhr.setRequestHeader("content-type", "multipart/form-data; charset=utf-8; boundary=" + boundary);
xhr.sendAsBinary( formData );
如果我们通过 FB.api(...) 示例发布状态消息,则字符确实编码正确。
感谢帮助。