I am new to Azure. I am using the following part of the code to upload a file to Azure Blob.
public async Task<byte[]> UploadResultFile(string fileName, byte[] data)
{
if (StringUtilities.isBlankOrNull(fileName))
{
throw new EmptyStringException("File name cannot be empty or null");
}
// Creates a BlobServiceClient object which will be used to create a container client
BlobServiceClient blobServiceClient = new BlobServiceClient(config.StorageConnectionString);
// Create the container and return a container client object
BlobContainerClient containerClient = blobServiceClient.GetBlobContainerClient(config.ResultContainer);
// Create a local file in the ./data/ directory for uploading and downloading
string localFilePath = Path.Combine(Experiment.DataFolder, fileName);
// Write text to the file
// Adding a check to write a data in a file only if data is not equal to null
// This is important as we need to re-use this method to upload a file in which data has already been written
if (data != null)
{
File.WriteAllBytes(localFilePath, data);
}
// Get a reference to a blob
BlobClient blobClient = containerClient.GetBlobClient(fileName);
// Open the file and upload its data
// FileStream uploadFileStream = File.OpenRead(localFilePath);
using FileStream uploadFileStream = File.OpenRead(localFilePath);
await blobClient.UploadAsync(uploadFileStream, true);
uploadFileStream.Close();
return Encoding.ASCII.GetBytes(blobClient.Uri.ToString());
}
}
But it is throwing an issue on uploadFileStream as following :
uploadFilestream.ReadOut threw an exception of type 'System.InvalidOAperationException'
uploadFilestream.WriteOut threw an exception of type 'System.InvalidOAperationException'
Subsequently, the console is throwing the following exception :
The I/O operation has been aborted because of either a thread exit or an application request
Caught an exception: 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.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: The I/O operation has been aborted because of either a thread exit or an application request.. ---> System.Net.Sockets.SocketException (995): The I/O operation has been aborted because of either a thread exit or an application request.
Any help in identifying and solving the issue will be highly appreciated.