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);
}
);
};