© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
4 replies
v0fbu1vm

❔ Upload large files to azure storage!

Does anyone have a method that uploads large files to azure storage efficiently? I'm using
Azure.Storage.Blobs
Azure.Storage.Blobs
Here is the current method
public async Task<Uri?> UploadFileAsync(string containerName, string fileName, Stream stream,
        CancellationToken cancellationToken)
    {
        try
        {
            var containerClient = _blobService.GetBlobContainerClient(containerName);
            await containerClient.CreateIfNotExistsAsync(cancellationToken: cancellationToken);
            var blobClient = containerClient.GetBlockBlobClient(fileName);
            
            var options = new BlobUploadOptions
            {
                TransferOptions = new StorageTransferOptions
                {
                    MaximumConcurrency = 16, // Adjust the concurrency level as needed
                    MaximumTransferSize = 4 * 1024 * 1024, // 4MB chunk size
                },
            };

            await blobClient.UploadAsync(stream, options, cancellationToken);
            return blobClient.Uri;
        }
        catch (Exception ex)
        {
            return null;
        }
    }
public async Task<Uri?> UploadFileAsync(string containerName, string fileName, Stream stream,
        CancellationToken cancellationToken)
    {
        try
        {
            var containerClient = _blobService.GetBlobContainerClient(containerName);
            await containerClient.CreateIfNotExistsAsync(cancellationToken: cancellationToken);
            var blobClient = containerClient.GetBlockBlobClient(fileName);
            
            var options = new BlobUploadOptions
            {
                TransferOptions = new StorageTransferOptions
                {
                    MaximumConcurrency = 16, // Adjust the concurrency level as needed
                    MaximumTransferSize = 4 * 1024 * 1024, // 4MB chunk size
                },
            };

            await blobClient.UploadAsync(stream, options, cancellationToken);
            return blobClient.Uri;
        }
        catch (Exception ex)
        {
            return null;
        }
    }
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,828Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

How to upload files to Azure Blob Storage?
C#CC# / help
4w ago
❔ Upload super large files to asp net core
C#CC# / help
4y ago
Azure Appserice 502 when upload large file [Answered]
C#CC# / help
4y ago
Background upload of an IFormFile to Azure blob storage
C#CC# / help
2y ago