我试图检索,然后POST
一个JPEG图像到Foursquare的https://api.foursquare.com/v2/photos/add
端点使用Axios在节点。我试着爱可信(和邮差)的一些方法,但总是收到Missing file upload
同样的错误响应:检索然后POST照片到Foursquare与Axios签入
{
"meta": {
"code": 400,
"errorType": "other",
"errorDetail": "Missing file upload",
"requestId": "NNNNNNNNNNNNNNNNNNNNN" // not the true requestId
},
"notifications": [
{
"type": "notificationTray",
"item": {
"unreadCount": 0
}
}
],
"response": {}
}
的图像是使用谷歌静态地图API创建,检索与爱可信GET
要求:
const image = await axios.get(imageURL, {
responseType: "arraybuffer"
});
这是包装在async
函数并成功返回缓冲区。的数据被读入一个Buffer
并转换为字符串:
const imageData = new Buffer(image, "binary").toString();
Here's an example imageData
string。我也尝试将字符串转换为base64
。
的字符串是POST
版的Foursquare的端点:
const postPhoto = await axios.post(
"https://developer.foursquare.com/docs/api/photos/add?
checkinId=1234&
oauth_token=[TOKEN]&
v=YYYYMMDD",
imageData,
{
headers: { "Content-Type": "image/jpeg" }
}
);
其中checkinId
,oauth_token
和v
PARAMS都是有效的。
我已经尝试了不同的Content-Type
值,base64
编码imageData
和其他几个解决方案在论坛和在这里发现SO(大多数是几岁),但没有任何作品。响应errorDetail总是表示Missing file upload
。
问题可能在于如何构造POST
请求,但我也可能错误地请求/处理图像数据。第二(或第三或第四)眼睛检查我把这一起会是超级有用。