我试图使用API来添加照片至四方的网页上传照片:四方丢失的文件上传/ InvalidPhotoFormat错误,同时通过API
{ meta: { code: 400, errorType: 'other', errorDetail: 'Missing file upload', requestId: '561fe6c1498e097824456e38' }, notifications: [ { type: 'notificationTray', item: [Object] } ], response: {} }
谁能请告诉我,我做错了什么?
更新:
var queryObj = {'oauth_token': accessToken, v: '20151009', 'pageId': platformProfileId};
request({
url: url, //URL to hit
qs: queryObj, //query obj
method: 'POST',
headers: { 'Content-Type': 'image/jpeg' },
body: b64content
}, function(error, response, body){
if(error) {
console.log(error);
return cb(error);
} else {
if(typeof body != 'object') {
body = JSON.parse(body);
}
console.log(body);
if(('meta' in body) && ('code' in body['meta']) && (body['meta']['code'] != 200)) {
return callback_inner("error");
}
var mediaIdStr = body['response']['id'];
return callback_inner(null, mediaIdStr);
}
});
试图发送图像后邮件正文但即使如此,它不工作。
更新2:
var b64mediaFilesArr = results.C;
async.map(b64mediaFilesArr, function(b64content, callback_inner){
var imagename = new Date() + '.jpg';
var url = "https://api.foursquare.com/v2/photos/add";
var formObj = {
'oauth_token': accessToken,
'v': '20151009',
'pageId': platformProfileId,
'photo': {
value: b64content,
options: {
filename: imagename,
contentType: 'image/jpeg'
}
}
};
request({
url: url, //URL to hit
formData: formObj, //form data
method: 'POST',
headers: { 'Content-Type': 'image/jpeg' }
}, function(error, response, body){
if(error) {
console.log(error);
return cb(error);
} else {
if(typeof body != 'object') {
body = JSON.parse(body);
}
console.log(body);
if(('meta' in body) && ('code' in body['meta']) && (body['meta']['code'] != 200)) {
return callback_inner("error");
}
var mediaIdStr = body['response']['id'];
return callback_inner(null, mediaIdStr);
}
});
如果我使用上面的代码,再有就是在响应变化:
{ meta: { code: 400, errorType: 'param_error', errorDetail: 'InvalidPhotoFormat: Unable to determine photo type', requestId: '56207798498ee45703ab6059' }, notifications: [ { type: 'notificationTray', item: [Object] } ], response: {} }
我要在此之后疯狂。任何人都可以请帮我吗?
解决方案
除了下面接受的答案,我解决了问题编码的base64。对于那些在你的web应用程序中使用base64编码图像数据的人,你需要发送图像的原始二进制代表到Foursquare。这个答案帮助我做到了。 Convert Binary.toString('encode64') back to Binary
所以我应该使用哪些参数有关的图像数据发送? –
该照片不被传入其中一个参数中。图像数据作为HTTP请求的POST消息正文发送。有关HTTP请求的更多信息,请参阅http://en.wikipedia.org/wiki/HTTP_request#Request_message。 –
我试着发送身体的图像数据,但即使那样它不工作。请看看我更新的代码 –