c# - 错误:(412)当前在 blob 上存在租约,请求中未指定租约 ID
问题描述
我正在读取/写入 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 的租约,以便另一个操作现在可以写入它
谢谢!
解决方案
请在方法的参数中包含Lease Id
blob 。所以你的代码会是这样的:AccessCondition
UploadTextAsync
await blob.UploadTextAsync("Some Content", Encoding.UTF8, new AccessCondition()
{
LeaseId = leaseResult
}, new BlobRequestOptions(), new OperationContext());
推荐阅读
- r - 同时生成多个 ARIMA 预测。我可以将它们存储在数组中以备将来使用吗?
- python - 如何按城市或地区前缀获取所有可能的经纬度地址?
- xml - 从一个应用程序到另一个应用程序的数据传输中的 XML 安全性
- python-3.x - Python:使用嵌套的子标签将 xml 展平为 csv
- angular - 订阅后服务值仍未定义
- python - Pywhatkit查询虚拟文字库助手
- reactjs - npm react-barcodes 打印条形码
- r - R - 在 data.table 中的多个列上应用 diff() 函数或等效的自定义函数
- angular - 与 Angular Service Worker 一起使用时,Azure AD 身份验证中的无限循环
- satellite-image - 在使用卫星图像的视听项目中如何以及是否有必要将“这里”归功于?