SAS キーを使用して Azure BLOB からダウンロードしています。Web ロール インスタンスから、Azure ストレージからストリーミングされた BLOB を取得し、ブラウザーに直接ストリーミングしています。小さなファイルでは問題なく動作しますが、大きなファイル (この場合は 1.7GB) をダウンロードしようとすると、次の StorageException が発生します。
{Microsoft.WindowsAzure.Storage.StorageException: Unable to read data from the transport connection: The connection was closed. ---> System.IO.IOException: Unable to read data from the transport connection: The connection was closed.
at System.Net.ConnectStream.EndRead(IAsyncResult asyncResult)
at Microsoft.WindowsAzure.Storage.Core.Util.StreamExtensions.WriteToSync(Stream stream, Stream toStream, Nullable`1 maxLength, Nullable`1 expiryTime, Boolean calculateMd5, Boolean syncRead, OperationContext operationContext, StreamDescriptor streamCopyState)
at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](StorageCommandBase`1 cmd, IRetryPolicy policy, OperationContext operationContext)
--- End of inner exception stack trace ---
at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](StorageCommandBase`1 cmd, IRetryPolicy policy, OperationContext operationContext)
at Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob.DownloadRangeToStream(Stream target, Nullable`1 offset, Nullable`1 length, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext)
ここに私の呼び出しコードがあります:
try
{
Blob = new Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob(new Uri(BlobSasUri));
httpResponse.Clear();
httpResponse.ClearHeaders();
httpResponse.ClearContent();
httpResponse.BufferOutput = false;
httpResponse.ContentType = Utilities.GetMIMEType(FileName);
string contentDisposition;
var browser = context.HttpContext.Request.Browser.Browser;
var version = context.HttpContext.Request.Browser.Version;
if (browser == "IE" && (version == "7.0" || version == "8.0" || version == "9.0"))
contentDisposition = "attachment; filename=" + Uri.EscapeDataString(FileName);
else if (browser == "Safari")
contentDisposition = "attachment; filename=" + FileName;
else
{
// Android Chrome browser unable to use UTF-8 encoding
if (Regex.IsMatch(context.HttpContext.Request.UserAgent, @"Android") &&
Regex.IsMatch(context.HttpContext.Request.UserAgent, @"Chrome"))
{
contentDisposition = "attachment; filename=" + Uri.EscapeDataString(FileName).Replace("'", Uri.HexEscape('\''));
}
else
{
// This is RFC5987 format, specifying use of utf-8. Apostrophes must be encoded for Chrome.
contentDisposition = "attachment; filename*=UTF-8''" +
Uri.EscapeDataString(FileName).Replace("'", Uri.HexEscape('\''));
}
}
httpResponse.AddHeader("Content-Disposition", contentDisposition);
httpResponse.AddHeader("Content-Length", eBFile.FileSize.ToString(CultureInfo.InvariantCulture));
Blob.DownloadToStream(
httpResponse.OutputStream
);
// More gracefully ends the http request
httpApp.CompleteRequest();
}
catch (Exception ex)
{
throw ex;
}
Azure ライブラリ ストリームが途中で終了する原因について何か考えはありますか? 私のダウンロード速度はまともな30Mbpsです。とても有難い!