【发布时间】:2023-03-14 00:46:01
【问题描述】:
我正在读取/写入 blob 存储中的文件,并且遇到了 AcquireLeaseAsync 和 BreakLeaseAsync 的问题。我认为这就是我调用 AcquireLeaseAsync 的方式,但不知道为什么。
这是我的代码
CloudBlockBlob blob = // get reference to blob
// I want to acquire a lease on the blob until I am done,
//the parameter null in this case means infinite until breaking
string leaseResult = await blob.AcquireLeaseAsync(null, Guid.NewGuid().ToString());
// get content
string previousContent = await blob.DownloadTextAsync();
// do other stuff
// write new content, **but exception is thrown here**
await blob.UploadTextAsync("new content");
// break a lease on the blob as soon as possible, code never gets here
this.blob.BreakLeaseAsync(TimeSpan.FromMilliseconds(1));
UploadTextAsync 抛出的异常是:
“远程服务器返回错误:(412) 当前存在对 blob 的租约,请求中未指定租约 ID。”
查看UploadTextAsync 的文档,我看不到在哪里传递租约ID 以允许这样做。
谁能告诉我我需要做什么才能完成:
- 获取 blob 的租约,以便当前上下文只能写入它
- 从 blob 下载文本
- 在 blob 上上传文本
- 打破对 blob 的租约,以便另一个操作现在可以写入它
谢谢!
【问题讨论】:
标签: c# azure azure-blob-storage