-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Azure Functions (node) doesn't process binary data properly #294
Comments
Can you try this with the Content-Type set to "application/octet-stream" ? |
Indeed, if the content type is set to "application/octet-stream" it works. But why does it fail when Content-Type is more specific, for example "image/png"? "application/octet-stream" isn't telling the web app anything other than it is some binary data. If req.headers looks like this, it fails:
Or is the function host logic simply saying: If content type equals "application/octet-stream" treat HTTP body as binary file, otherwise as string? |
Yeah, there's specific logic around content-type "application/octet-stream" and those starting with "multipart" (https://github.com/Azure/azure-functions-host/blob/dev/src/WebJobs.Script/Extensions/HttpRequestExtensions.cs). I'll go ahead and close this thread since this solved the issue. Please feel free to reopen/start new thread if you have any more questions around this. |
Alright, then just out of interest, is this behavior documented somewhere? Because I'd assume this can be a potential pitfall for users who send data to an Azure Function by a browser (at least the browsers I've seen will by default set the Content-Type header based on the actual file type and not only to "application/octet-stream") or use e.g. Postman for testing. And why do we set |
Tagging @mhoeger and @pragnagopa who might have answers to this. |
reopening and moving to nodejs worker repo to provide a code sample. |
"isRaw" is about the response but not the request. I also need to double check if that guidance is now deprecated, because "isRaw" was a V1 feature. The "dataType" property is applied by some bindings, but isn't for the HttpBinding, which is misleading :\ agreed that we should document which ones we special-case to send as binary. |
@alrod and @AnatoliB - this will be super important to get into the next major version release - very much a pain today. Either by making all "body" the raw version or actually populating "rawBody" with the bytes version. This capability is related, most other language workers consume raw bytes for body but we couldn't do the same on this because of legacy behavior. |
Same problem here, I've searching a past day looking for this strange behavior on google as my binary upload doesn't have the same size and contents of my original one. |
I also ran into this issue and was very surprised to learn about this unexpected behavior. After all, the current behavior is very surprising: Even if In my scenario, I don't have control over the caller, i.e. I cannot enforce that my Function will get I understand that backwards compatibility is important. So maybe a solution could be to introduce |
Hi folks we're working on a new programming model for Node.js and one of the benefits will be to improve the experience around backwards compatibility and breaking changes. We should be able to react much faster to requests like this, and you should have more choice when you adopt the breaking changes. See here for more details: #568 It's one part of our larger effort (tracked by #480) which is currently under way. We will go through the list of breaking changes as we're finishing up the new model and likely address a good chunk of them. |
FYI we took two approaches to address this issue:
|
I can´t believe it, I tried ALL, fs, Buffer, all library to read xls file and not work. was just add Thanks! |
Hi all, just FYI the change for this just finished rolling out in Azure as a part of host v4.14.0. binary data will always be available in the new |
UPDATE: Per final design, we added a property
request.bufferBody
that you can use to access the binary dataMy goal is to write a function which processes the binary HTTP body (for example, an image). I've created the function using the func CLI (version 2.7.2254) doing the following:
My function.json looks like this:
My expectation would be that now req.body is a Buffer but when I check the type
typeof req.body;
it seems to be a string. Therefore, my attempt to save this file to disk like you see below in my index.ts also fails:
Test:
What's the correct way of processing binary data in a node based Azure Function?
The text was updated successfully, but these errors were encountered: