According to facebook documentation, http://developers.facebook.com/docs/reference/api/album/, to upload a photo, source type should be "multipart/form-data"
Now I got the image file from client to server side in node.js using 'connect-form'. and I am using 'facebook-js' module to upload the photo to facebook as,
app.post('/', func开发者_高级运维tion(req, res, next){
req.form.complete(function(err, fields, files){
if (err) {
next(err);
} else {
console.log('uploaded ', files.source.filename, 'to', files.source.path);
fb.apiCall('POST', '/me/photos',
{access_token: fields.access_token,
message: fields.message,
**source:files.source**},
function (error, response, body) {
if (error) {
console.log('Error in facebook Photo UPLOAD', error);
return;
}
res.redirect('back');
}
);
The above throws an error as files.source is not encoded as "multipart/form-data".. May I know what needs to be done here ? Do I have to put the file into memory and then use it in source ?
You can't do this using the current implementation of facebook-js
(which I'm assuming is this). It uses the node request library which doesn't appear to have native support for sending multipart/form-data
HTTP requests. You can implement multipart/form-data submission (see this for a longer example) but you'll probably need to fork the original library.
精彩评论