node-flickrapi icon indicating copy to clipboard operation
node-flickrapi copied to clipboard

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

Open kodie opened this issue 9 years ago • 12 comments

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.

kodie avatar Jan 08 '17 02:01 kodie

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.

Pomax avatar Jan 08 '17 18:01 Pomax

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.

kodie avatar Jan 08 '17 20:01 kodie

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

LahiruBandara avatar Apr 28 '17 12:04 LahiruBandara

@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?

Pomax avatar Apr 28 '17 15:04 Pomax

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

madkoding avatar Sep 29 '17 00:09 madkoding

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

madkoding avatar Sep 29 '17 14:09 madkoding

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

Pomax avatar Sep 29 '17 17:09 Pomax

There is @Pomax o/

madkoding avatar Sep 29 '17 18:09 madkoding

@madkoding why did you close both PRs?

Pomax avatar Oct 01 '17 18:10 Pomax

closed by mistake :P

madkoding avatar Oct 02 '17 13:10 madkoding

hehe, gotcha =)

Pomax avatar Oct 02 '17 16:10 Pomax

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

truonghoangphuc avatar Mar 01 '18 10:03 truonghoangphuc