简体   繁体   中英

photo upload options to facebook in node.js

I am building a site with nodejs and mongodb and using facebook for authentication.. my users will be required to upload certain photo and others will be able to view them .

Since I am using facebook, I am wondering if I should allow users to upload their photos to their facebook profile and I'll save the links into the database so that later on other users can view this.

Is this the right approach ? or should I use flickr or picasa or something else ?

I have to do this in javascript and I know facebook has support for this.

Please let me know what you think.

EDIT:

Hi,

Finally I found the module connect-form to upload the file to the server and then uploading the file to facebook using the module facebook-js . I found fb.api for "/me/feed" works perfectly in node.js server. But when I tried to use the graph api for "/me/photos" as mentioned in http://developers.facebook.com/docs/reference/api/album/ , I got the error. That is because it expects the source to be in "multipart/form-data". In my html, it is already "multipart/form-data", otherwise I'll not get the file in the server side. In the server side, however, I am not very sure about how to embed this in FB.api... what should be the "source" parameter in FB.api "/me/ photos" ? I tried this with "source:files.source" as mentioned in my example. But it does not work. may be i am missing something very silly...

app.post('/', function(req, res, next){

  req.form.complete(function(err, fields, files){
    if (err) {
      next(err);
    } else {

      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;
            }
          console.log('facebook RESPONSE :', response);
          console.log('facebook BODY :', body);
          res.redirect('back');
          //res.render('done', {body: body});
        }
      );

    }
  });

You have the option to upload photos to Facebook using the url, read the following article:
https://developers.facebook.com/blog/post/526/

I suggest to use some CDN for photos like Amazon S3 which is very reliable and scalable. Then you can optionally have it on Facebook too with a simple API call (don't forget about extended permissions to upload photos in this case)

hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM