[英]Azure blob storage DownloadTextAsync with BlobRequestOptions
Using azure blob storage and the Azure SDK, I currently am downloading a string like so: 使用azure blob存储和Azure SDK,我当前正在下载一个字符串,如下所示:
var storageAccount = CloudStorageAccount.Parse(connectionString);
var blobClient = storageAccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference(containerName);
var blockBlob = container.GetBlockBlobReference(blobUid);
var text = await blockBlob.DownloadTextAsync();
I want to pass in a blobRequestOptions to set a custom retry policy so it would look like this: 我想传入blobRequestOptions来设置自定义重试策略,因此它看起来像这样:
var storageAccount = CloudStorageAccount.Parse(connectionString);
var blobClient = storageAccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference(containerName);
var blockBlob = container.GetBlockBlobReference(blobUid);
var blobRequestOptions = new BlobRequestOptions()
{
RetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(5), 3)
};
var text await blockBlob.DownloadTextAsync(encoding, accessCondition, blobRequestOptions, operationContext);
My problem is I am not sure what to pass in for encoding, accessCondition or operationContext. 我的问题是我不确定要为编码,accessCondition或operationContext传入什么。 I have looked at the documentation ( https://msdn.microsoft.com/en-us/library/dn434829.aspx ) and did a bunch of searching but I cannot figure out what to pass in.
我查看了文档( https://msdn.microsoft.com/zh-cn/library/dn434829.aspx ),并进行了大量搜索,但我不知道要输入什么。
Encoding: My data is just json in Us-En so I think I would be fine with ACSII or UTF-8 but I cannot find if azure has a default I should be using. 编码:在Us-En中,我的数据只是json,所以我认为使用ACSII或UTF-8会很好,但是我无法确定azure是否应使用默认值。
AccessCondition and OperationContext: No idea what I should be passing in. AccessCondition和OperationContext:不知道我应该传递什么。
Or maybe there is a better way to do what I am trying to do without using the overloaded DownloadTextAsync. 或者,也许有一种更好的方法可以执行我想做的事情,而无需使用重载的DownloadTextAsync。
When I have a problem like this and I'm lucky enough that the SDK is open-source, I usually check out the source code. 当我遇到这样的问题并且很幸运该SDK是开源的时,我通常会检查源代码。 Source code for the Azure Storage SDK is here:
Azure存储SDK的源代码在这里:
https://github.com/Azure/azure-storage-net https://github.com/Azure/azure-storage-net
So this is the method that you are calling: 因此,这是您要调用的方法:
public virtual Task<string> DownloadTextAsync(CancellationToken cancellationToken)
{
return AsyncExtensions.TaskFromApm(this.BeginDownloadText, this.EndDownloadText, cancellationToken);
}
This just basically converts the BeginDownloadText
method from the old APL model to the new TPL-based call. 这基本上只是将
BeginDownloadText
方法从旧的APL模型转换为新的基于TPL的调用。 If you check out BeginDownloadText: 如果您签出BeginDownloadText:
public virtual ICancellableAsyncResult BeginDownloadText(AsyncCallback callback, object state)
{
return this.BeginDownloadText(null /* encoding */, null /* accessCondition */, null /* options */, null /* operationContext */, callback, state);
}
You can see that they are explicitly specifying null
values for the encoding, the accessCondition and the operationContext. 您可以看到它们为编码,accessCondition和operationContext明确指定了
null
值。 You can drill even further down if you want, but I'd say you're OK using null
for the parameters you don't need. 如果需要,您甚至可以进一步进行深入研究,但是我说您可以使用
null
作为不需要的参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.