【问题标题】:Use Azure Function to Export CSV使用 Azure 函数导出 CSV
【发布时间】:2021-02-13 13:18:27
【问题描述】:

我试图编写一个访问 azure blob 存储的 azure 函数,并使用生成的 url。这样一旦用户输入了这个 url,它就会从 azure Blob Storage 下载一个 csv 文件到调用者的本地 PC。 从到目前为止我编写的 azure 函数中,它能够访问 blob 存储上的数据。有谁知道如何让它导出 csv 给调用用户?

【问题讨论】:

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


    【解决方案1】:

    你需要创建FileContentResult

    public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequest req, ILogger log)
    {
        string csv;
    
        //Access azure blog storage and create in csv content
    
        byte[] filebytes = Encoding.UTF8.GetBytes(csv);
    
        return new FileContentResult(filebytes, "application/octet-stream") {
            FileDownloadName = "Export.csv"
        };
    }
    

    【讨论】:

    • 感谢您的回复。你知道如何在 Python 代码中做到这一点吗?
    【解决方案2】:

    这个很快conversion 可能对你有帮助

    import azure.functions as func
    
    async def main(req: func.HttpRequest) -> func.HttpResponse:
        // access azure blog storage and get the csv read as string
        filebytes= bytes(csv, 'utf-8')
    
        return func.HttpResponse(body=filebytes, status_code=200, mimetype='application/octet-stream')
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-30
      • 2021-12-31
      • 2015-07-26
      • 1970-01-01
      • 2018-04-10
      • 2019-12-12
      • 2020-04-13
      • 1970-01-01
      相关资源
      最近更新 更多