我試圖檢索,然後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
請求,但我也可能錯誤地請求/處理圖像數據。第二(或第三或第四)眼睛檢查我把這一起會是超級有用。