Azure Function App:无法导入 BlobServiceClient、BlobClient

问题描述 投票:0回答:1

我有一个 Azure 函数,如下所示:

import azure.functions as func
import logging
import os
import tempfile
import subprocess
import json
from pathlib import Path
import glob  

app = func.FunctionApp()


@app.blob_trigger(
    arg_name="myblob",
    path="cssinputbuckettest/{name}.MF4",
    connection="cssdatalakestoragegen2_STORAGE",
)
def BlobTrigger1(myblob: func.InputStream):
    logging.info(
        f"Python blob trigger function processed blob "
        f"Name: {myblob.name} "
        f"Blob Size: {myblob.length} bytes"
    )
...

我可以毫无问题地发布我的函数。

但是,在我的脚本中,我需要使用

BlobServiceClient, BlobClient
下载除触发器 blob 之外的其他文件。因此,我在其他导入语句之后添加以下语句:

from azure.storage.blob import BlobServiceClient, BlobClient

但是,当执行此操作时,我的发布失败并且没有推送任何功能。我应该以不同的方式将其他 blob 下载到我的函数中吗?

azure azure-functions azure-blob-trigger
1个回答
0
投票

在Python函数中,确保您的代码语法正确并确保您使用正确的包。

这对我有用。

我正在上传

*.txt
文件并下载
download.json
文件将在 blob 容器中可用。

function_app.py

import azure.functions as func
import logging
from azure.storage.blob import *
import os

app= func.FunctionApp()

@app.blob_trigger(arg_name="myblob", path="download/{name}.txt",
                               connection="Storage_conn") 
def BlobTrigger(myblob: func.InputStream):
    logging.info(f"Python blob trigger function processed blob"
                f"Name: {myblob.name}")
    
    client = BlobServiceClient.from_connection_string(os.getenv("Storage_conn"))
    container_client = client.get_container_client("download")
    blob_client = container_client.get_blob_client("download.json")

    downloaded = blob_client.download_blob()

    content = downloaded.readall()

    logging.info(f"Contant of the file: {content}")

OUTPUT

© www.soinside.com 2019 - 2024. All rights reserved.