1

我正在使用 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;
}

关于什么可能导致天蓝色库流过早退出的任何想法?我的下载速度是不错的 30Mbps。非常感激!

4

1 回答 1

1

我终于能够通过为 CloudBlockBlob.DownloadToStream() 方法指定一个“超时”值(现在为 20 分钟)来解决这个问题。

于 2013-09-01T02:26:08.927 回答