I have created a Blazor Server Project in .NET6. In my project I need to upload files mostly exe files to the azure container. Here is the code:
// Get the file from file picker
var file = e.Files.FirstOrDefault();
BlobServiceClient blobServiceClient = new BlobServiceClient(connectionString);
// Get or create the container in azure
BlobContainerClient blobContainer = blobServiceClient.GetBlobContainerClient("uploadfiles");
var containerResponse = await blobContainer.CreateIfNotExistsAsync();
if (containerResponse != null && containerResponse.GetRawResponse().Status == 201)
{
await blobContainer.SetAccessPolicyAsync(Azure.Storage.Blobs.Models.PublicAccessType.Blob);
}
// Create the blob in container
BlobClient blobClient = blobContainer.GetBlobClient(file.Name);
//Read file contents
using var stream = file.OpenReadStream();
using (var memoryStream = new MemoryStream())
{
await stream.CopyToAsync(memoryStream);
byte[] fileBytes = memoryStream.ToArray();
BinaryData uploadData = new BinaryData(fileBytes);
Response<BlobContentInfo> uploadResponse = await blobClient.UploadAsync(uploadData, true);
}
Now the problem is, I can upload small sized file to the container. But when comes to large file, for example 5 MB, I can't upload the file to the container. It says the below error:
Supplied file with size 5275768 bytes exceeds the maximum of 512000 bytes.
Now one solution could be making smaller chunks. But in that case I am not sure the file will be corrupted or not.
Can anyone help me by providing any solution.