gpt4 book ai didi

exception - 从 azure blob 下载时,我得到 "Unable to read data from the transport connection: The connection was closed."

转载 作者:行者123 更新时间:2023-12-03 03:18:25 27 4
gpt4 key购买 nike

我使用 SAS key 从 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,还不错。非常感谢!

最佳答案

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

关于exception - 从 azure blob 下载时,我得到 "Unable to read data from the transport connection: The connection was closed.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18538080/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com