0
我使用amazon api網關設置了一個API,並且希望將數據放入kinesis流中。亞馬遜的api網關已經內置了對它的支持。但是當我試圖把json數據給出「序列化異常」。如何將使用Amazon API網關的json數據放入Kinesis流
var data = {"ua_platform":"iPhone","ua_browsercodename":"Mozilla","ua_browserlanguage":"en-us","ua_header":"Mozilla\/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit\/601.1.46 (KHTML, like Gecko) Version\/9.0 Mobile\/13B143 Safari\/601.1","ua_browsername":"Netscape","key":"livestream_hindi",,"datetime_ut":"1458711871","datetime_dt":"2016-03-23","value":"15","source":"0","browser":"Mobile Safari-9.0.","os":"iOS-9.1.","device_detail":"iPhone Apple iPhone"};
var json = JSON.stringify(data);
var params = { 'ContentType' : 'application/json','Access-Control-Allow-Headers' : 'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token'};
var body = {"Data":json,
"StreamName":"XXXXXX",
"PartitionKey":"XXXX"
};
在此之後我做一個PUT請求
apigClient.functionPut(params, body, additionalParams)
.then(function(result){
//This is where you would put a success callback
console.log("success");
}).catch(function(result){
//This is where you would put an error callback
console.log("catch");
});
的API提供200 OK與序列異常一起。它在放入請求中聲明瞭「Data」鍵在body變量中將只接受「blob」類型。現在我也嘗試將JSON數據轉換爲BLOB,但沒有運氣。
我無法弄清楚我做錯了什麼。請幫忙。
謝謝你的幫助設立API網關在AWS官方文檔室壁運動前的演練。但我糾正了這個問題。我需要將字符串化數據轉換爲base64編碼數據以便將其推送到流中。我使用JAVASCRIPT:btoa()函數,它按預期工作。 –