I have problems reading the Content/Data with Python and the BlobTrigger. I use local environment and followed the documentation (https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob-trigger?tabs=python). The function is listening and also fires successfully, when I upload a file to the local blob emulator. I also can get the filepath/filename in a variable, but can’t read the content of the uploaded file.
When I try to get the content, it always shows an empty string or array.
So this is my functions.json file:
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "myblob",
"type": "blobTrigger",
"direction": "in",
"path": "log/SystemLog/{name}",
"connection": ""
}
]
}
This is my init.py file: import logging import azure.functions as func
def main(myblob: func.InputStream):
print(myblob.name)
print(myblob.length)
print(myblob.readlines())
This is what get printed in the console:
[2021-10-29T07:27:25.053Z] Host lock lease acquired by instance ID '000000000000000000000000F86KCB51'.
[2021-10-29T07:27:25.124Z] Worker process started and initialized.
[2021-10-29T07:27:46.941Z] Executing 'Functions.BlobTriggerLocalTest' (Reason='New blob detected: log/SystemLog/testfile.txt', Id=3981bd58-accb-4c9c-b3e4-fe33b1a74522)
[2021-10-29T07:27:46.948Z] Trigger Details: MessageId: 7c575bad-88b7-46d4-b5bf-67b90fe0ab4d, DequeueCount: 1, InsertionTime: 2021-10-29T07:27:46.000+00:00, BlobCreated: 2021-10-29T07:27:43.000+00:00, BlobLastModified: 2021-10-29T07:27:43.000+00:00
[2021-10-29T07:27:47.032Z] log/SystemLog/testfile.txt
[2021-10-29T07:27:47.037Z] None
[2021-10-29T07:27:47.042Z] []
[2021-10-29T07:27:47.068Z] Executed 'Functions.BlobTriggerLocalTest' (Succeeded, Id=3981bd58-accb-4c9c-b3e4-fe33b1a74522, Duration=204ms)
I tried some solutions to get along with the problem.
First Thing was to go along with the documentation https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob-input?tabs=python. But the changes in the functions.json files are not fully clearly for me. I tried to input
{
"name": "inputblob",
"type": "blob",
"dataType": "binary",
"path": "log/SystemLog/{name}",
"connection": "",
"direction": "in"
},
in the functions.json file and added the inputblob as a second parameter to the main-method, but len(inputblob) also prints a 0.
I think I also could use and import the BlobServiceClient from azure.storage.blob. But I guess the BlobServiceClient would need a separate connection string and I want to avoid that.