Azure Functions blob 输入绑定,没有错误,没有创建文件
Azure Functions blob input binding, no errors, no files created
我正在尝试让 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)
编辑:
我不知道默认情况下有一个与函数关联的存储帐户,文件出现在那里。
通过对本地计算机 visual studio 2019 中的共享代码进行以下更改并添加“Microsoft.Azure.WebJobs.Extensions.Storage(4.0.5)”依赖项,我们能够在存储中创建一个 blob帐户并在触发 Http 触发器时将数据写入创建的 blob。
这里是示例输出以供参考:
我正在尝试让 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)
编辑: 我不知道默认情况下有一个与函数关联的存储帐户,文件出现在那里。
通过对本地计算机 visual studio 2019 中的共享代码进行以下更改并添加“Microsoft.Azure.WebJobs.Extensions.Storage(4.0.5)”依赖项,我们能够在存储中创建一个 blob帐户并在触发 Http 触发器时将数据写入创建的 blob。
这里是示例输出以供参考: