【发布时间】:2020-09-30 19:06:33
【问题描述】:
这方面的文档似乎很混乱。使用 CloudBlobContainer.AcquireLease 方法现在已弃用的 Microsoft.Azure.Storage.Blob nuget 包似乎可以做到这一点。
更新后的BlobLeaseClient 有一个Acquire() 方法,它声明:
Acquire(TimeSpan, RequestConditions, CancellationToken) 操作 获得 blob 或容器的租约。
但不清楚应该如何使用它。尽管我找到了已弃用软件包的示例,但我找不到任何此类示例。
目前我有这个:
//injected using AddBlobServiceClient, etc. Uses DefaultAzureCredential
private BlobContainerClient blobContainerClient;
blobContainerClient = blobServiceClient.GetBlobContainerClient("containerName");
BlobLeaseClient blc = blobContainerClient.GetBlobLeaseClient();
//throws exception here
BlobLease bl = await blc.AcquireAsync(new TimeSpan(0, 0, 30));
但是当我运行它时,我会得到:
The value for one of the HTTP headers is not in the correct format.
RequestId:<guid>
Time:2020-09-30T10:28:47.8781946Z
Status: 400 (The value for one of the HTTP headers is not in the correct format.)
ErrorCode: InvalidHeaderValue
Headers:
Server: Windows-Azure-Blob/1.0,Microsoft-HTTPAPI/2.0
x-ms-request-id: <guid>
x-ms-client-request-id: <guid>
x-ms-version: 2019-12-12
x-ms-error-code: InvalidHeaderValue
Date: Wed, 30 Sep 2020 10:28:47 GMT
Content-Length: 328
Content-Type: application/xml
我也不确定这是否会租用 bob,因为我从未指定要租用的 blob。
有人知道如何在这种情况下正确使用 BlobLeaseClient 吗?
【问题讨论】:
标签: c# azure azure-blob-storage