Node.js を使用して base64 画像を FaceBook ページにアップロードしようとしています。ファイルシステムからファイルを読み取る必要がある場合(つまり、 fs.readFileSync('c:\a.jpg') を使用)、すべてのマルチパートデータなどでアップロードを機能させることができました
ただし、base64 でエンコードされた画像を使用してアップロードしようとすると、次のエラーが表示されます。{"error":{"message":"(#1) An unknown error occurred","type":"OAuthException","code":1}}
それをバイナリに変換してnew Buffer(b64string, 'base64');
アップロードしようとしましたが、うまくいきません。
私はこれに3日間苦労しているので、どんな助けでも大歓迎です。
編集:base64をバイナリに変換して正常にアップロードする方法を誰かが知っていれば、それもうまくいきます。
編集:コードスニペット
var postDetails = separator + newlineConstant + 'Content-Disposition: form-data;name="access_token"' + newlineConstant + newlineConstant + accessToken + newlineConstant + separator;
postDetails = postDetails + newlineConstant + 'Content-Disposition: form-data; name="message"' + newlineConstant + newlineConstant + message + newlineConstant;
//Add the Image information
var fileDetailsString = '';
var index = 0;
var multipartBody = new Buffer(0);
images.forEach(function (currentImage) {
fileDetailsString = fileDetailsString + separator + newlineConstant + 'Content-Disposition: file; name="source"; filename="Image' + index + '"' + newlineConstant + 'Content-Type: image/jpeg' + newlineConstant + newlineConstant;
index++;
multipartBody = Buffer.concat([multipartBody, new Buffer(fileDetailsString), currentImage]); //This is what I would use if Bianry data was passed in
currentImage = new Buffer (currentImage.toString('base64'), 'base64'); // The following lines are what I would use for base64 image being passed in (The appropriate lines would be enabled/disabled if I was using Binary/base64)
multipartBody = Buffer.concat([multipartBody, new Buffer(fileDetailsString), currentImage]);
});
multipartBody = Buffer.concat([new Buffer(postDetails), multipartBody, new Buffer(footer)]);