2

我将如何在快递应用程序中做同样的事情?也就是说,将文件发布到 facebook:

curl -F 'access_token=xyz' \
    -F 'source=@file.png' \
    -F 'message=Caption for the photo' \
    https://graph.facebook.com/me/photos

我正在使用以下内容从 repo 中的示例上传文件:

app.post('/', function(req, res, next){
 req.form.complete(function(err, fields, files){
   if (err) {
     next(err);
   } else {
     console.log('\nuploaded %s to %s'
       ,  files.image.filename
       , files.image.path);
     res.redirect('back');
   }
 });
})
4

2 回答 2

2

看一下request-module,它(几乎)太容易了:

fs.readStream('file.png').pipe(request.post('http://graph.facebook.com/me/photos'))

这将创建一个对给定 URL 的 POST 请求并file.png通过它进行流式传输。添加其余字段应该相当简单。

于 2011-11-15T16:54:52.623 回答
0

您可以使用 Node.js 创建 HTTP 请求。请参阅文档中的以下示例:

http://nodejs.org/docs/v0.4.0/api/http.html#http.request

于 2011-02-14T21:09:57.180 回答