I am trying to load two images in, one uploaded image (trigger) and one from a hardcoded blob location.
def main(blobtrig: func.InputStream, medianimage: func.InputStream, blobout: func.Out[bytes]):
logging.info(f"Python blob trigger function processed blob \n"
f"Stuff: {blobtrig.__dict__}\n")
logging.info(f"Next Blob Name \n"
f"Stuff: {medianimage.__dict__}\n")
input_image = blobtrig
base_image = Image.open(input_image)
med_image = medianimage
logging.info(f"Med image read is {type(med_image)}")
median_image = Image.open(med_image)
The first Image.open(input_image) works, but the second doesn't. I think the medianimage Inputstream is not pointing to the right place. My functions.json is like this...
{"scriptFile": "__init__.py","bindings": [
{
"name": "blobtrig",
"type": "blobTrigger",
"direction": "in",
"path": "facility-model-image-data/{name}",
"connection": "AzureWebJobsStorage"
},
{
"type": "blob",
"direction": "in",
"name": "medianimage",
"path": "facility-model-image-data/median.jpg",
"connection": "AzureWebJobsStorage"
},
{
"type": "blob",
"direction": "out",
"name": "blobout",
"path": "processed-images/{rand-guid}.jpg",
"connection": "AzureWebJobsStorage"
}],"disabled": false, "scriptFile": "__init__.py"}
But the files printed by python logging are both the same even though medianimage should be pointing to a completely different file:
[02/02/2020 18:39:36] Stuff: {'_io': <_io.BytesIO object at 0x7f2cabdc0620>,
'_name': 'facility-model-image-data/test_gray.jpg', '_length': 152606,
'_uri': 'https://functionimageprocessor.blob.core.windows.net/facility-model-image-data/test_gray.jpg'}
[02/02/2020 18:39:36]
[02/02/2020 18:39:36] Next Blob Name
[02/02/2020 18:39:36] Stuff: {'_io': <_io.BytesIO object at 0x7f2cabdc0f10>,
'_name': 'facility-model-image-data/test_gray.jpg', '_length': 152606,
'_uri': 'https://functionimageprocessor.blob.core.windows.net/facility-model-image-data/test_gray.jpg'}
and the script fails here...
[02/02/2020 18:39:36] Stack: File "/usr/lib/azure-functions-core-tools/workers/python/3.7/LINUX/X64/azure_functions_worker/dispatcher.py", line 312, in _handle__invocation_request
[02/02/2020 18:39:36] self.__run_sync_func, invocation_id, fi.func, args)
[02/02/2020 18:39:36] File "/usr/lib/python3.7/concurrent/futures/thread.py", line 57, in run
[02/02/2020 18:39:36] result = self.fn(*self.args, **self.kwargs)
[02/02/2020 18:39:36] File "/usr/lib/azure-functions-core-tools/workers/python/3.7/LINUX/X64/azure_functions_worker/dispatcher.py", line 431, in __run_sync_func
[02/02/2020 18:39:36] return func(**params)
[02/02/2020 18:39:36] File "/home/peter/Documents/Python/dataset-processing/functions/imageuploadtrigger/__init__.py", line 35, in main
[02/02/2020 18:39:36] median_image = Image.open(med_image)#Image.frombytes('RGBA', (636,795), med_image, 'raw')
Been struggling with this for ages so any help would be great! Also sorry if the question formatting isn't the best (first time posting here).
This looks about right. I was unable to find any examples of using 2 different blobBindings with python, unfortunately. but both the blobTrigger and blobBinding are read via func.InputStream
. My guess would be - this doesn't really work with python (perhaps a bug?). You can file an issue on Github.
Couple of workarounds:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With