【问题标题】:Azure Functions blob input binding, no errors, no files createdAzure Functions Blob 输入绑定,没有错误,没有创建文件
【发布时间】:2021-11-12 13:24:40
【问题描述】:

我正在尝试让 Azure 函数在 Blob 存储上创建一个具有给定文件名的文件。我没有收到任何错误,但文件似乎也没有出现。 它在本地或部署时不起作用。

我对设置 blob 存储及其访问权限不是很有经验,我缺少什么?

using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;

namespace My.Functions
{
    public static class UploadGhost
    {
        [FunctionName("UploadGhost")]
        [StorageAccount("AzureWebJobsStorage")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log,
            IBinder binder)
        {
        
            string filename = "ghostsdev/myFile.txt";
            var attribute = new BlobAttribute(filename, FileAccess.Write);

            attribute.Connection = "AzureWebJobsStorage";
            using (var writer = await binder.BindAsync<TextWriter>(attribute))
            {
                writer.Write("myData");
                log.LogInformation("I made a file! or did I... ");
            }

            return new OkObjectResult("Executed without errors!");
        }
    }
}

输出:

2021-09-17T17:13:07  Welcome, you are now connected to log-streaming service. The default timeout is 2 hours. Change the timeout with the App Setting SCM_LOGSTREAM_TIMEOUT (in seconds). 
2021-09-17T17:13:15.436 [Information] Executing 'UploadGhost' (Reason='This function was programmatically called via the host APIs.', Id=3d956f6a-e9c5-42fc-bf8d-d1ff55810f9c)
2021-09-17T17:13:15.849 [Information] I made a file! or did I...
2021-09-17T17:13:16.030 [Information] Executed 'UploadGhost' (Succeeded, Id=3d956f6a-e9c5-42fc-bf8d-d1ff55810f9c, Duration=615ms)

编辑: 我不知道默认情况下有一个与函数关联的存储帐户,并且文件出现在那里。

【问题讨论】:

    标签: azure-functions azure-blob-storage


    【解决方案1】:

    通过在我的本地机器 Visual Studio 2019 中对共享代码进行以下更改并添加“Microsoft.Azure.WebJobs.Extensions.Storage(4.0.5)”依赖项,我们能够在存储帐户中创建一个 blob & 触发 Http 触发器时将数据写入创建的 blob。

    这是供参考的示例输出:

    【讨论】:

    • 我不知道默认情况下有一个与函数关联的存储帐户,并且文件出现在那里。谢谢。
    猜你喜欢
    • 2018-05-17
    • 2017-04-06
    • 2011-05-11
    • 2021-11-02
    • 1970-01-01
    • 2012-11-13
    • 1970-01-01
    • 1970-01-01
    • 2014-05-12
    相关资源
    最近更新 更多