0

I need to upload a large file(up 4GB) using Blazor. Please in your answers using the new version of Azure Storage SDK (v12 Azure.Storage.Blobs NuGet package.)

In my case, the old version will not work Azure Storage SDK (v11 WindowsAzure.Storage NuGet package.)

Requirement`

  1. Upload file in Blazor UI
  2. Send that file to the server side via API
  3. Store that file in Azure Blob Storage on the server side.

I try a few ways to do this but I didn't manage it. Is there any way to do this?

What I tried`

  1. Send the file itself(2GB) to API but out of memory exception (google says do not do this way, bad practice)

2.Cut the file as chunks and send it to API, the first part of sending works but I can't collect them all together as one file and store it in Azure Blob Storage (I will have a memory issue).

If there is a way to store it in Azure Blob for example store the first part of chunks then update that file and write other parts sequentially in one file on Azure Blob not service memory. In the end, I will have one large file in Blob.

1 Answers1

1

If there is a way to store it in Azure Blob for example store the first part of chunks then update that file and write other parts sequentially in one file on Azure Blob not service memory.

Yes. This is how Block Blobs work in Azure Storage.

Basically what you will need to do is send chunks (called blocks in Azure Storage) of the data to your API and directly save those chunks in blob storage using BlockBlobClient.StageBlockAsync. There is no need for you to save those chunks in your API. You will need to maintain the block ids of the chunks you are uploading in your Blazor application.

Once all the chunks (blocks) are uploaded, you will need to send the block ids to your API and will need to call BlockBlobClient.CommitBlockListAsync from your API to tell Azure Blob Storage to combine all blocks together to create a blob.

To learn more about creating block blobs by uploading blocks, you may find these links useful:

Gaurav Mantri
  • 128,066
  • 12
  • 206
  • 241