You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python Azure Functions使用BlobTrigger无法读取Blob内容问题求助

解决方案
  • 调整functions.json中Blob Trigger绑定配置,新增dataType字段指定按二进制流读取内容:
{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "myblob",
      "type": "blobTrigger",
      "direction": "in",
      "path": "log/SystemLog/{name}",
      "connection": "",
      "dataType": "binary"
    }
  ]
}
  • 升级本地Python Azure Functions SDK到最新稳定版,低于1.7.0的版本存在本地Blob流读取异常的已知问题:
    pip install --upgrade azure-functions
  • 修改__init__.py的内容读取逻辑,先读取完整字节流再处理,避免游标提前偏移导致内容为空:
import logging
import azure.functions as func

def main(myblob: func.InputStream):    
    print(myblob.name)
    # 读取完整Blob字节流
    blob_content = myblob.read()
    print(len(blob_content))
    # 文本类型可解码输出
    if blob_content:
        print(blob_content.decode('utf-8'))
  • 替换本地存储模拟器为最新版Azurite V3+,旧版已停止维护的Azure Storage Emulator存在和新版Functions运行时的兼容问题,会导致Blob流读取为空。

完成以上操作后重启本地Functions运行时,重新上传Blob测试即可正常读取内容,无需额外新增输入绑定,也不需要手动调用Blob SDK拉取内容。

内容的提问来源于stack exchange,提问作者Denise

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 05:15:03