【发布时间】: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