1

Me having strange problem while adding photo to foursquare checkin via node.js. When I use image files less than 10KB the photo got uploaded to that checkin but anything more than that in size just give me a BAD Gateway response from foursquare api server...

var http = require('http');
 var step = require('step');
 var request = require('request');

 exports.foursquarephoto = function(req, res){
        step(
                function(){

                     //var image_url = 'http://www.a2hosting.com/images/uploads/landing_images/node.js-hosting.png'; // size 9KB                     
                     var image_url = 'http://upload.wikimedia.org/wikipedia/commons/1/16/AsterNovi-belgii-flower-1mb.jpg'; // size 1MB


                    request.get({
                        url: image_url,
                        encoding: null
                    }, this);

                },
                function(err, response, body){

                    if(err) {

                    }

                    var imagename = new Date() + '.jpg';
                    var buffer = body;
                    var ImageBuffer = new Buffer(buffer, 'base64');

                    var r = request.post('https://api.foursquare.com/v2/photos/add' , this);
                    var form = r.form();
                    // foursquare post
                    // https://foursquare.com/winz_dean/checkin/52241e7b11d2264c2b178d90

                    form.append('checkinId', '52241e7b11d2264c2b178d90');                   
                    form.append('photo', ImageBuffer, { filename: imagename });                 
                    form.append('oauth_token', 'FGDS4XZF0U0DUQKZG1TCYFWIEUPZXCQG3SLMCUQHAESN2JLO');

                },
                function(err, response, body){

                    if(err) {
                        res.send(err);
                    }

                    res.send(200, body);
                }
        ); 
     };
user2682546
  • 31
  • 2
  • 4
  • Hmm. Are you meeting all the other requirements set on https://developer.foursquare.com/docs/photos/add? Is your Content-Type correct? – octopi Sep 03 '13 at 23:36
  • @octopi yes b/c if that the case the small image file won't got added in first place. you can see in the above code, i have used 2 images... 1st one is working but for 2nd one its failing... – user2682546 Sep 04 '13 at 09:43
  • I'm also facing a similar issue. Can anyone please take a look at http://stackoverflow.com/questions/33155303/foursquare-missing-file-upload-error-while-uploading-photo-through-api – dark_shadow Oct 16 '15 at 03:50
  • @octopi: Can we send image data as base64 encoded string to foursquare ? – dark_shadow Oct 16 '15 at 07:31

0 Answers0