【问题标题】:how to read the Azure blob file with Azure function in python?如何在 python 中使用 Azure 函数读取 Azure blob 文件?
【发布时间】:2021-12-18 21:00:09
【问题描述】:

我是 Azure 云的新手。现在我希望创建一个工作流程:将音频文件上传到 blob --> 调用 Blob 触发器 --> 部署的 python 函数读取上传的音频文件并提取谐波 --> 谐波输出为 json 文件并保存在另一个容器中. 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}")

它返回一个错误:

异常:UnicodeDecodeError:“utf-8”编解码器无法解码位置 40 中的字节 0x80:无效起始字节。

我的 function.json 是:

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

【问题讨论】:

  • 为什么本地运行代码(audioread.audio_open("File saved path"))没有报错?但是,一旦我在 Azure Function (audioread.audio_open("inputblob") 上运行,它就不起作用了。是我喂 blob 的方式错误吗?
  • 确保将您的音频文件上传为 Blob,其中包含具有正确 content typecontent encoding 的二进制数据,请参阅 documentation

标签: python audio azure-functions azure-blob-storage


【解决方案1】:

输入绑定允许您读取 Blob 存储数据作为 Azure 函数的输入。

更多详情请参考此文档:https://docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob-input?tabs=python

并确保在将音频文件作为 blob 上传到 azure 存储时提供了正确的内容类型和编码

更多详情请参考document

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-06-01
    • 1970-01-01
    • 2018-07-30
    • 2021-10-05
    • 2018-03-07
    • 1970-01-01
    • 2018-01-08
    • 2021-10-18
    相关资源
    最近更新 更多