简体   繁体   English

如何在 python 中使用 Azure 函数读取 Azure blob 文件?

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

I am new in Azure cloud.我是 Azure 云的新手。 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.现在我希望创建一个工作流程:将音频文件上传到 blob --> 调用 Blob 触发器 --> 部署的 python 函数读取上传的音频文件并提取谐波 --> 谐波输出为 json 文件并保存在另一个容器中. Blow is my code but it doesn't work: Blow 是我的代码,但它不起作用:

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.例外:UnicodeDecodeError:“utf-8”编解码器无法解码位置 40 中的字节 0x80:起始字节无效。

my function.json is:我的 function.json 是:

{
  "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.输入绑定允许您读取 Blob 存储数据作为 Azure 函数的输入。

For more details refer this document : https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob-input?tabs=python有关更多详细信息,请参阅此文档: 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并确保在将音频文件作为 blob 上传到 azure 存储中时提供了正确的内容类型和编码

For more details refer this document有关更多详细信息,请参阅此文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从Azure Function Python动态读取blob文件 - How to dynamically read blob file from Azure Function Python 如何从 Azure function 在 Z23EEEB4347BDD26BDDFC6B75 - How to read xlsx blob into pandas from Azure function in python 如何从 Azure Python function blob 输入绑定中读取镶木地板文件? - How to read parquet file from Azure Python function blob input binding? 如何使用 python 和 pandas read_fwf ZC1C42542074E68384F5D1 处理位于 Azure blob 存储中的文件 - How to process a file located in Azure blob Storage using python with pandas read_fwf function 如何使用 Python 从 Azure Blob 容器读取文件 - How to read a file from Azure Blob Container using Python Python:如何从 azure blob 存储中读取一个 doc 文件? - Python: how to read a doc file from azure blob storage? 从 python 中的 azure blob 存储读取文件 - read file from azure blob storage in python 如何使用带有 python 的 Azure 函数写入 blob 容器中的文本文件? - How to write to a text file in a blob container using Azure function with python? 如何使用 Azure 函数从 Blob 存储中读取 json 文件 Python - How to read json file from blob storage using Azure Functions Blob Trigger with Python AZURE Function 从 AZURE BLOB 读取 XLSX - AZURE Function read XLSX from AZURE BLOB
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM