简体   繁体   中英

how to read the Azure blob file with Azure function in python?

I am new in Azure cloud. Now I hope to create a work flow: upload a audio file to the blob --> Blob trigger is invoked --> deployed python function read the upload audio file and extract harmonics --> harmonics output as json file and save in another container. Blow is my code but it doesn't work:

import logging
import azure.function as func
import audio_read

def main(myblob: func.InputStream):

    logging.info(f"Python blob trigger function processed blob \n"
                 f"Name: {myblob.name}\n"
                 f"Blob Size: {myblob.length} bytes")
    
    audio_info = audioread.audio_open(myblob.read())
    logging.info(f"{audio_info}")

It returns me an error:

Exception: UnicodeDecodeError: "utf-8" codec can't decode byte 0x80 in position 40: invalid start byte.

my function.json is:

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "myblob",
      "type": "blobTrigger",
      "direction": "in",
      "path": "examplecontainer/{name}",
      "connection": "AzureWebJobsStorage"
    }
  ]
}

The input binding allows you to read blob storage data as input to an Azure Function.

For more details refer this document : https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob-input?tabs=python

And make sure that you have given the proper content type and encoding while uploading audio file as blob in azure storage

For more details refer this document

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM