我创建了一个在本地运行的函数,我可以为 HTTP 触发函数执行此操作,但是当涉及 BlobTriggered 时,我总是遇到同样的错误。
我正在使用 Azurite 在http://127.0.0.1:10000端点模拟 Azure 中的 Blob 服务我拥有的代码如下:
local.settings.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
}
}
CSharp代码如下:
using System;
using System.IO;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;
namespace Company.Function
{
public static class BlobTriggerCSharp1
{
[FunctionName("BlobTriggerCSharp1")]
public static void Run([BlobTrigger("samples-workitems/{name}", Connection = "AzureWebJobsStorage")]Stream myBlob, string name, ILogger log)
{
log.LogInformation($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes");
}
}
}
我正在尝试在容器上的 Microsoft File Azure Storage 上创建新文件:
local-emulator -> Blob Containers -> samples-workitems -> 创建一个新项目
因此,当我在某个时间后运行时,总是会收到以下错误:函数:
BlobTriggerCSharp1: blobTrigger
For detailed output, run func with --verbose flag.
[2021-05-06T11:29:19.279Z] Host lock lease acquired by instance ID '000000000000000000000000182E0241'.
[2021-05-06T11:29:47.002Z] An unhandled exception has occurred. Host is shutting down.
[2021-05-06T11:29:47.003Z] Microsoft.WindowsAzure.Storage: No connection could be made because the target machine actively refused it. System.Net.Http: No connection could be made because the target machine actively refused it. System.Private.CoreLib: No connection could be made because the target machine actively refused it.
编辑
当我尝试使用 Azurite 从本地 Azure 函数访问本地存储帐户时
var connection = new
Uri("http://127.0.0.1:10000/devstoreaccount1/test123");
try {
BlobContainerClient client = new BlobContainerClient(connection,
new DefaultAzureCredential());
await foreach (BlobItem blobItem in client.GetBlobsAsync())
{
Console.WriteLine("\t" + blobItem.Name);
}
打电话时client.GetBlobAsync
我收到错误:
“不能在没有 HTTPS 的情况下使用 TokenCredential。”
编辑2
我这样做的方法是遵循本教程:https ://blog.jongallant.com/2020/04/local-azure-storage-development-with-azurite-azuresdks-storage-explorer/
但是我无法设置 Visual Studio Code 的 Azurite 扩展来使用它。我需要在单独的命令行中执行此操作,并且需要通过 https 执行此操作。