Pomax / node-flickrapi

A node.js (and client-library) implementation of the Flickr API with oauth API key authentication and API method proxying
177 stars 51 forks source link

Uploading an image results in an empty array and the application hanging #101

Open kodie opened 7 years ago

kodie commented 7 years ago

Here is my code:

var Flickr = require("flickrapi"),
    flickrOptions = {
      "user_id": "(Hidden)",
      "api_key": "(Hidden)",
      "api_secret": "(Hidden)",
      "access_token": "(Hidden)",
      "access_token_secret": "(Hidden)",
      "permissions": "write"
    };

Flickr.authenticate(flickrOptions, function(error, flickr) {
  if (!error) {
    var uploadOptions = {
      photos: [{
        title: "test",
        photo: __dirname + "/image.png"
      }]
    };

    Flickr.upload(uploadOptions, flickrOptions, function(err, res) {
      if (!err) {
        console.log(res);
      } else { throw err; }
    });
  } else { throw error; }
});

After a couple of seconds I get [] printed out in the console and the application never finishes running so I have to hit CTRL+C to force end the app.

Pomax commented 7 years ago

Technically neither of those things are signs that your upload went wrong, although they suggest something else might be wrong. If there were no errors, presumably the upload worked and your Flickr page will now show that image in your stream. Is it not there?

The code that does the actual post and leads to a result callback is https://github.com/Pomax/node-flickrapi/blob/master/src/utils.js#L409-L419, so seeing an empty array suggests you do hit https://github.com/Pomax/node-flickrapi/blob/master/src/utils.js#L416 but the response is not what the code expects. In this case I'd recommend doing a quick code modification: slot

} else if (body.indexOf('rsp stat="ok"')>-1) {
  console.log(body);
  data = parseInt(body.split.....
}

and see what that's in that response body.

kodie commented 7 years ago

The image was never uploaded. I was able to get the image to upload using the same api credentials with https://github.com/flickr/flickr-sdk

I'll give your code change a try and see what happens.

LahiruBandara commented 7 years ago

I have the exact same issue. Moving out to https://github.com/flickr/flickr-sdk

Pomax commented 7 years ago

@LahiruBandara cool - before you do, or while, can you supply the information that @kodie ended up not following up with so that perhaps this bug can still be fixed for others that run into it?

madkoding commented 7 years ago

same here... response is empty on image upload = [ ] also, the "uploaded image" never appears in flickr

madkoding commented 7 years ago

Guys, i add a pull request replacing the current response parsing using the xml2json module... also will give the correct error response (that no show in the actual code, that's why response is empty) @Pomax

Pomax commented 7 years ago

nice, if you can update that to a single PR I'll be happy to review and merge.

madkoding commented 7 years ago

There is @Pomax o/

Pomax commented 7 years ago

@madkoding why did you close both PRs?

madkoding commented 7 years ago

closed by mistake :P

Pomax commented 7 years ago

hehe, gotcha =)

truonghoangphuc commented 6 years ago

How is the status now? I just got this issue.