Azure函数绑定可以将文件夹而不是文件作为路径

发布于 2025-02-06 04:15:50 字数 86 浏览 2 评论 0原文

目前,我需要在文件夹中的不同文件中读取数据并返回结果。文件夹中有大量文件。因此,是否可以将文件夹用作Azure函数绑定中的路径?[在此处输入图像说明] [1]

Currently I need to read data from different files in a folder and return the result. There are quite a large number of files in the folder. So is it possible to use the folder as path in Azure function bindings??[enter image description here][1]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

掐死时间 2025-02-13 04:15:50

以下是使用HTTP触发器可以使用的解决方法之一。

import logging

import azure.functions as func
from azure.storage.blob import BlockBlobService

ACCOUNT_NAME = "<YOUR ACCOUNT NAME>"
SAS_TOKEN='<YOUR SAS TOKEN>'

blob_service = BlockBlobService(account_name=ACCOUNT_NAME,account_key=None,sas_token=SAS_TOKEN)

def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')
    blobnames=""
    
    name = req.params.get('name')
    if not name:
        try:
            req_body = req.get_json()
        except ValueError:
           return func.HttpResponse(f"Enter the container you are searching for")
        else:
            name = req_body.get('name') 
                       
    print("\nList blobs in the container")
    generator = blob_service.list_blobs(container_name=name) #lists the blobs inside containers
    for blob in generator:
        blobnames+=blob.name+"\n"

    if name:        
            return func.HttpResponse(f"{blobnames}"
        )
        
    else:
        return func.HttpResponse(
             "There is no container present with this name",
             status_code=200
        )

结果:

”在此处输入图像描述

Below is one of the workaround that is possible using HTTP Trigger.

import logging

import azure.functions as func
from azure.storage.blob import BlockBlobService

ACCOUNT_NAME = "<YOUR ACCOUNT NAME>"
SAS_TOKEN='<YOUR SAS TOKEN>'

blob_service = BlockBlobService(account_name=ACCOUNT_NAME,account_key=None,sas_token=SAS_TOKEN)

def main(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')
    blobnames=""
    
    name = req.params.get('name')
    if not name:
        try:
            req_body = req.get_json()
        except ValueError:
           return func.HttpResponse(f"Enter the container you are searching for")
        else:
            name = req_body.get('name') 
                       
    print("\nList blobs in the container")
    generator = blob_service.list_blobs(container_name=name) #lists the blobs inside containers
    for blob in generator:
        blobnames+=blob.name+"\n"

    if name:        
            return func.HttpResponse(f"{blobnames}"
        )
        
    else:
        return func.HttpResponse(
             "There is no container present with this name",
             status_code=200
        )

RESULT:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文