【发布时间】:2021-03-31 22:19:44
【问题描述】:
我正在尝试使用 .net SDK V12 将大文件存储到 Azure Blob。这个程序可以上传小文件,没有异常,但是大文件抛出异常。你有解决这个问题的办法吗?
BlobClient blobClient = containerClient.GetBlobClient(uploadFileName);
using (FileStream uploadFileStream = File.OpenRead(localFilePath))
{
await blobClient.UploadAsync(uploadFileStream, true);
var meta = new Dictionary<string, string>();
meta["LastWriteTime"] = new FileInfo(localFilePath).LastWriteTime.ToString("yyyy/MM/dd HH:mm:ss");
meta["CreationTime"] = new FileInfo(localFilePath).CreationTime.ToString("yyyy/MM/dd HH:mm:ss");
await blobClient.SetMetadataAsync(meta);
}
我想知道的不是.NET SDK V11的解决方案,而是V12。
这个异常如下,文件大小为91.6MB
System.AggregateException: Retry failed after 6 tries. (The operation was canceled.) (The operation was canceled.) (The operation was canceled.) (The operation was canceled.) (The operation was canceled.) (The operation was canceled.)
---> System.Threading.Tasks.TaskCanceledException: The operation was canceled.
---> System.Net.Http.HttpRequestException: Error while copying content to a stream.
---> System.IO.IOException: Unable to read data from the transport connection:
---> System.Net.Sockets.SocketException (995):
--- End of inner exception stack trace ---
at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
at System.Net.Security.SslStream.<WriteSingleChunk>g__CompleteAsync|210_1[TWriteAdapter](ValueTask writeTask, Byte[] bufferToReturn)
at System.Net.Security.SslStream.WriteAsyncChunked[TWriteAdapter](TWriteAdapter writeAdapter, ReadOnlyMemory`1 buffer)
at System.Net.Security.SslStream.WriteAsyncInternal[TWriteAdapter](TWriteAdapter writeAdapter, ReadOnlyMemory`1 buffer)
at System.Net.Http.HttpConnection.WriteAsync(ReadOnlyMemory`1 source)
at System.IO.Stream.CopyToAsyncInternal(Stream destination, Int32 bufferSize, CancellationToken cancellationToken)
at Azure.Core.RequestContent.StreamContent.WriteToAsync(Stream stream, CancellationToken cancellation)
at Azure.Core.Pipeline.HttpClientTransport.PipelineRequest.PipelineContentAdapter.SerializeToStreamAsync(Stream stream, TransportContext context)
at System.Net.Http.HttpContent.CopyToAsyncCore(ValueTask copyTask)
【问题讨论】:
-
先分享异常怎么样?!
-
你的文件有多大?我用
using (FileStream file = File.OpenRead(path)) { await blob.UploadAsync(file); }成功上传了文件(大约443.53 MiB)。 -
@silent 感谢您的评论。我添加了例外。
-
@PamelaPeng 谢谢你的评论。文件大小为 91.6MB。
标签: c# .net azure blob storage