-
Notifications
You must be signed in to change notification settings - Fork 107
Description
When input parameter of Azure Function that is bound to Blob is typed as bytes, the actual type is str.
Official documentation states that the parameter should be typed as InputStream. This is the default when no typing is specified. However, we can specify str type and get the string. If we specify the type of input variable as bytes, the actual type is also str, which makes using the raw binary data difficult.
Azure Functions in C# support many different types, which makes development much more convenient. It would be nice to have the same functionality in Python to be consistent.
Proposed solutions:
- Allow to specify
bytesas input type, fix incorrect typing and add this to documentation - Throw type error exception if typing is specified incorrectly
Investigative information
- Core Tools version: 3.0.2852
Repro steps
Create the following http-triggered Azure Function:
Code
import logging
import azure.functions as func
def main(inblb: bytes , req: func.HttpRequest) -> func.HttpResponse:
logging.info(f"Type of input object is {type(inblb)}")
return func.HttpResponse(f"Type of input object is {type(inblb)}",status_code=200)inblb is bound to Azure Blob Storage:
function.json
{
"scriptFile": "__init__.py",
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "$return"
},
{
"type": "blob",
"direction": "in",
"name": "inblb",
"path": "thecontainer/thefile",
"connection": "demoazfuncstorage_STORAGE"
}
]
}
Expected behavior
Either one of:
- [suggested] Type of input object is
bytes - Exception is thrown to indicate incorrect typing
Actual behavior
Type of input object is str
Known workarounds
Use func.InputStream as type of blob-bound parameter, and obtain the content of blob using read() method.