I am trying to large file to Azure Blob using .net SDK V12. This program can upload small files, without exception, But larget file threw exception. Do you have a solution of this problem.
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);
}
I want to know not the solution of using .NET SDK V11, but V12.
This exception is as follows and the file size is 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)
I faced the same error when using StorageConnectionString
, like this:
BlobServiceClient blobServiceClient = new BlobServiceClient(StorageConnectionString);
BlobContainerClient container = blobServiceClient.GetBlobContainerClient(BlobContainerName);
BlobClient blob = container.GetBlobClient(BlobName);
// Open the file and upload its data
using (FileStream file = File.OpenRead(path))
{
await blob.UploadAsync(file);
}
I changed to use StorageSharedKeyCredential
, it worked.
string accountName = "";
string accountKey = "";
Uri serviceUri = new Uri("https://xxx.blob.core.windows.net/");
// Create a SharedKeyCredential that we can use to authenticate
StorageSharedKeyCredential credential = new StorageSharedKeyCredential(accountName, accountKey);
// Create a client that can authenticate with a connection string
BlobServiceClient blobServiceClient = new BlobServiceClient(serviceUri, credential);
// BlobServiceClient blobServiceClient = new BlobServiceClient(StorageConnectionString);
BlobContainerClient container = blobServiceClient.GetBlobContainerClient(BlobContainerName);
BlobClient blob = container.GetBlobClient(BlobName);
// Open the file and upload its data
using (FileStream file = File.OpenRead(path))
{
await blob.UploadAsync(file);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.