gpt4 book ai didi

Azure Function Blob 存储连接 : The format of value '*' is invalid

转载 作者:行者123 更新时间:2023-12-02 04:24:17 24 4
gpt4 key购买 nike

我正在编写一个 v2 Azure 函数,我将在其中访问 Azure Blob 存储。因为我遇到了麻烦,所以我将其简化为这个最小的示例。

namespace Test
{
public static class Function1
{
[FunctionName("Function1")]
public static async Task<IActionResult> Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "test")] HttpRequest req,
ILogger log)
{
var azureStorage = CloudStorageAccount.Parse("UseDevelopmentStorage=true");
var blobClient = azureStorage.CreateCloudBlobClient();
var container = blobClient.GetContainerReference("migrated-load-sets-localhost");
var blobReference = container.GetBlockBlobReference("11016093-2f6e-4631-97c1-04f8acfb2370");
var memoryStream = new MemoryStream();
var accessCondition = AccessCondition.GenerateIfExistsCondition();
var blobRequestOptions = new BlobRequestOptions();
await blobReference.DownloadToStreamAsync(memoryStream, accessCondition, blobRequestOptions, null);
var text = System.Text.Encoding.UTF8.GetString(memoryStream.ToArray());
return new OkObjectResult(text);
}
}
}

当我运行并点击这个时,我收到错误

System.Private.CoreLib: Exception while executing function: Function1. Microsoft.WindowsAzure.Storage: The format of value '*' is invalid. System.Net.Http: The format of value '*' is invalid.

如果我改变

var accessCondition = AccessCondition.GenerateIfExistsCondition();

成为

var accessCondition = AccessCondition.GenerateEmptyCondition();

它有效。

我在调试中观察到 accessCondition.IfMatchETag 等于 "*",所以看来这可能是罪魁祸首。

我使用AccessCondition.GenerateIfExistsCondition()时是否做错了什么,或者库中是否存在错误?

最佳答案

如果您需要在下载文件之前检查 blob 是否存在,您只需要

if(blobReference.ExistsAsync())
{
//Download
}

关于Azure Function Blob 存储连接 : The format of value '*' is invalid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56308537/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com