我正在使用NuGet程序包WindowsAzure.Storage
版本4.2.1。通過慢速網絡下載大文件時的StorageException
以下代碼嘗試從位於遙遠的數據中心的存儲容器中下載blob。
try
{
var blobRequestOptions = new BlobRequestOptions
{
RetryPolicy = new ExponentialRetry(TimeSpan.FromSeconds(5), 3),
MaximumExecutionTime = TimeSpan.FromMinutes(60),
ServerTimeout = TimeSpan.FromMinutes(60)
};
using (var fileStream = File.Create(localPath))
{
blockBlob.DownloadToStream(fileStream, null, blobRequestOptions);
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
但是,有時它下載了約10分鐘,然後它拋出以下異常:
Unhandled Exception: Microsoft.WindowsAzure.Storage.StorageException: The client could not finish the operation within specified timeout. ---> System.TimeoutException: The client could not finish the operation within specified timeout.
--- End of inner exception stack trace ---
at Microsoft.WindowsAzure.Storage.Core.Util.StorageAsyncResult`1.End()
at Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.EndUploadText(IAsyncResult asyncResult)
at Microsoft.WindowsAzure.Storage.Core.Util.AsyncExtensions.<>c__DisplayClass4.b__3(IAsyncResult ar)
--- End of stack trace from previous location where exception was thrown ---
我該如何解決這個問題?
blob有多大? –
@GauravMantri 500 MB左右 –
謝謝。是以塊的形式下載一個選項?基本上這個想法是,你以較小的塊下載這個大塊,然後在塊被下載時構建文件。 –