0

I changed my Azure function from using a blobTrigger input to a blob input. This change causes my function to fail. Using the previous binding (blobTrigger), the code works.

Input Binding:

{
  "name": "inblob",
  "type": "blob",
  "direction": "in",
  "path": "pre-processed-session-data/{queueTrigger}",
  "connection": "kinetyxdev01_STORAGE"
},

Previous Trigger Input Binding (Code works with this binding):

{
  "name": "inblob",
  "type": "blobTrigger",
  "direction": "in",
  "path": "pre-processed-session-data/{queueTrigger}",
  "connection": "kinetyxdev01_STORAGE"
},

Main Method:

def main(myitem: func.QueueMessage, inblob: func.InputStream):
    logging.info(f"Python blob trigger function processed blob \n"
                 f"Name: {inblob.name}\n"
                 f"Type: {type(inblob)}\n"
                 f"Blob Size: {inblob.length} bytes")
    # read in zip file
    logging.info(f"read in zip file")
    blob_bytes = inblob.read()
    blob_to_read = BytesIO(blob_bytes)
    zf = zipfile.ZipFile(blob_to_read) 

error message:

Executed 'Functions.ProcessSession' (Failed, Id=91ebae70-5ad1-4d26-81ff-dc1aa19e11d3, Duration=372ms)
System.Private.CoreLib: Exception while executing function: Functions.ProcessSession. System.Private.CoreLib: Result: Failure
Exception: BadZipFile: Bad magic number for central directory
Stack:   File "/usr/local/Cellar/azure-functions-core-tools@3/3.0.2881/workers/python/3.8/OSX/X64/azure_functions_worker/dispatcher.py", line 343, in _handle__invocation_request
    call_result = await self._loop.run_in_executor(
  File "/Users/omar/opt/anaconda3/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/Cellar/azure-functions-core-tools@3/3.0.2881/workers/python/3.8/OSX/X64/azure_functions_worker/dispatcher.py", line 480, in __run_sync_func
    return func(**params)
  File "/Users/omar/Documents/Kinetyx/OneDrive - Kinetyx Sciences Inc/programs/library-python-data-processing/ProcessSession/__init__.py", line 22, in main
    zf = zipfile.ZipFile(blob_to_read)
  File "/Users/omar/opt/anaconda3/lib/python3.8/zipfile.py", line 1268, in __init__
    self._RealGetContents()
  File "/Users/omar/opt/anaconda3/lib/python3.8/zipfile.py", line 1363, in _RealGetContents
    raise BadZipFile("Bad magic number for central directory")
Omar
  • 329
  • 1
  • 3
  • 10
  • Does this answer your question? [Bad magic number error with ZipFile module in Python](https://stackoverflow.com/questions/7703639/bad-magic-number-error-with-zipfile-module-in-python) – Tibebes. M Sep 22 '20 at 17:24
  • I think that further supports my theory that this is related to the missing meta data owing to the known azure I linked. – Omar Sep 22 '20 at 17:30
  • I print out the first 10 bytes of each input and they are identical: b'PK\x03\x04\x14\x00\x00\x00\x08\x00' I continue to believe this is related to the metadata and not the raw content inside the files. – Omar Sep 22 '20 at 18:00

1 Answers1

1

Changing the datatype to binary on the input binding fixed this problem:

{
  "name": "inblob",
  "type": "blob",
  "direction": "in",
  "dataType": "binary",
  "path": "***",
  "connection": "***"
},
Omar
  • 329
  • 1
  • 3
  • 10