我通过node.js向foursquare checkin添加照片时遇到了奇怪的问题。 当我使用小于10KB的图像文件时,照片被上传到该签入,但是除了大小之外的任何东西只是给我一个来自foursquare api服务器的BAD网关响应......
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);
}
);
};