如何解决如何使用BlobLeaseClient在Azure存储容器中租借单个Blob?
有关此问题的文档似乎非常混乱。似乎可以通过使用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,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
我也不确定这是要租借鲍勃,因为我没有指定要租借的blob。
有人知道如何在这种情况下正确使用BlobLeaseClient吗?
解决方法
首先,您需要获取对Blob的引用:
blobContainerClient = blobServiceClient.GetBlobContainerClient("containerName");
var blobClient = blobContainerClient.GetBlobClient("my.blob");
然后创建一个租赁客户并获得一个租赁:
var blc = blobClient.GetBlobLeaseClient();
var bl = await blc.AcquireAsync(TimeSpan.FromSeconds(30))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。