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字符串形式返回缓冲区。 –