An Azure Function HTTP binding reads from an Azure Blob Storage an image as a Base64 string.
data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxQTEhIUEhIUFBUV…K9rk8hCAEkjFMUYiEAI+nHIpsQh0AkisDYRTOiCAbWVtgCtI6IlkHh7LDTQXLH0EIQBj//2Q==
It converts it using a new Buffer:
const buf = new Buffer(pictureObj.data.split(",")[1], "base64");
Then it returns this buffer this way:
context.bindings.res = {
"status": 200,
"headers": {
"Content-Type": type || "image/jpeg"
},
"body": new Uint8Array(buf)
};
Unfortunately this doesn't work. setting "isRaw" didn't work either as well as returning the buffer (buf) itself. The error is 406 (Unacceptable) and the body is empty.
The question is this: how would one would return a base64 as binary image through an HTTP out binding?
Also, adding one more header (such as Content-Length) fails with this error:
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.