Azure函數HTTP綁定從Azure Blob存儲讀取圖像作爲Base64字符串。如何將Azure函數的base64圖像作爲二進制數據返回
data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxQTEhIUEhIUFBUV…K9rk8hCAEkjFMUYiEAI+nHIpsQh0AkisDYRTOiCAbWVtgCtI6IlkHh7LDTQXLH0EIQBj//2Q==
它把使用新的緩衝區它:
const buf = new Buffer(pictureObj.data.split(",")[1], "base64");
然後返回此緩衝區是這樣的:
context.bindings.res = {
"status": 200,
"headers": {
"Content-Type": type || "image/jpeg"
},
"body": new Uint8Array(buf)
};
可惜,這是行不通的。設置「isRaw」既不工作也不返回緩衝區(buf)本身。錯誤是406(不可接受),並且主體是空的。
現在的問題是:如何通過HTTP輸出綁定將base64作爲二進制圖像返回?
另外,再增加一個報頭(諸如內容長度)失敗,此錯誤:
info: Worker.Node.2a68d094-3858-406b-a0c5-a81497b3436b[0]
Worker 2a68d094-3858-406b-a0c5-a81497b3436b malformed message invocationResponse.outputData.data.http.headers: string{k:string} expected
[03/12/2017 02:44:32] A ScriptHost error has occurred
[03/12/2017 02:44:32] Error: Choose either to return a promise or call 'done'. Do not use both in your script.
[03/12/2017 02:44:32] Error: Choose either to return a promise or call 'done'. Do not use both in your script.
用application/octet-stream content-type進行實驗,結果是一樣的。 未設置content-type以base64字符串形式返回緩衝區。 –