Open ojha-ravi opened 8 years ago
attached_files
is a reference to the param name of a file that should be POSTed using multipart/form-data with the HTTP request. This only worked in the example because the actual upload example in the docs was a curl command that used -F 'file1=@cat.gif' -F 'file2=@dog.jpg'
to upload two files.request
object so file uploads could be attached. But it was rejected as @prabirshrestha wanted an alternate api pattern for attaching file uploads. Which I agree with, though I might want to review and change the idea for what syntax to use. Hi @dantman , thanks for your quick reply... I have tried posting with form-data to actually insert image in HTTP POST request which worked so i was little excited that this may also be possible.
var form = new FormData(); //Create multipart form
form.append('file', fs.createReadStream(picPaths[0])); //Put file
form.append('message', "Hello"); //Put message
var ACCESS_TOKEN = "ACCESS_TOKEN";
var options = {
method: 'post',
host: 'graph.facebook.com',
path: '{Object-ID}/photos' + '?access_token=' + ACCESS_TOKEN,
headers: form.getHeaders(),
}
var request = https.request(options, function(res) {
console.log(res, false, null);
});
form.pipe(request);
request.on('error', function(error) {
console.log(error);
});
Glad that you are thinking about this. Thanks again for your very detailed info.
Would you care to test out 1.1.0-alpha1
(use npm install fb@^1.1.0-alpha1
).
I've added upload support. You can pass a Buffer or a ReadableStream as value or an object containing { value: ..., options: { ... } }
where value
is a Buffer or a ReadableStream and options
can contain contentType
, filename
, and any other options available in formData
/form-data
. If you that for any of your params multipart/form-data will be used to upload.
FB.api('', 'post', {
batch: [{
method: "POST",
relative_url: "{Object-id}/feed",
body: "message=post one",
attached_files: 'file1'
}, {
method: "POST",
relative_url: "{Object-id}/feed",
body: "message=post two",
attached_files: 'file2'
}],
file1: fs.createReadStream('post1.jpg'),
file2: fs.createReadStream('post2.jpg')
}, function(res) {
if (!res || res.error) {
console.log(!res ? 'error occurred' : res.error);
return;
}
console.log(res[0]);
console.log(res[1]);
});
Hi @dantman , sry for late reply, i tried to follow steps that you suggested.
I am able to post two (or more) posts, but pic is not getting attached to the post.
Please suggest if i am missing something obvious. Thanks,
Hi @dantman , it works only if i change ...{Object-id}/feed...
to {Object-id}/photos
You should ask on SO what the proper graph API call is to publish a post with a photo attachment.
I don't see any documentation saying posting to */feed with an upload is the way to do that.
Hey Guys, i have been trying to post local photo(s) on fb with node terminal app in batch process with the following,
The error i am getting is following,
This is similar to the example given in fb docs titled under
Uploading binary data
. I think the title says that you need to upload binary files, which i don't know how to that, Any help?If i remove the
attached_files
from the code above it is able to create two post on fb on thatnode
If some has done this before can you please post the snapshot of your code. (Thanks) Please help me with this. Any help will really appreciated.
Similar Post