Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to upload append blob to azure without getting size limit exception?

public async Task<string> UploadDataAsync<T>(CloudBlobContainer container, string relativeUrl, List<T> reportData, string mimeType, string data, ILogger log)
    {
        string absoluteUri = string.Empty;
        byte[] bytes = Encoding.ASCII.GetBytes(data);
        using (var ms = new MemoryStream())
        {
            using (StreamWriter sw = new StreamWriter(ms))
            {
                sw.Write(data);
                sw.Flush();
                ms.Position = 0;

                CloudAppendBlob blob;
                blob = container.GetAppendBlobReference(relativeUrl);
                if (await blob.ExistsAsync())
                {
                    await blob.AppendBlockAsync(ms);
                    absoluteUri = blob.StorageUri.PrimaryUri.AbsoluteUri;
                }
                else
                {
                    CloudAppendBlob appBlob = await CreateEmptyFileAsync(container, relativeUrl, reportData, mimeType, log);
                    await appBlob.AppendBlockAsync(ms);
                    absoluteUri = appBlob.StorageUri.PrimaryUri.AbsoluteUri;
                }
            }
        }

        return absoluteUri;
    }

Getting this Exception –

Microsoft.WindowsAzure.Storage.StorageException: ‘The request body is too large and exceeds the maximum permissible limit.’
[External Code]
PDCGeoTabFunction.Services.UploadService.UploadDataAsync(Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer, string, System.Collections.Generic.List, string, string, Microsoft.Extensions.Logging.ILogger) in UploadService.cs
[External Code]
PDCGeoTabFunction.Services.SyncGeoTabDataService.GetZone(Geotab.Checkmate.API, string, string, string, Microsoft.Extensions.Logging.ILogger, string, string, string, string, System.Collections.Generic.List<Geotab.Checkmate.ObjectModel.Zone>) in SyncGeoTabDataService.cs

Please help.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Most likely you are getting this error is because the data that you are trying to upload is more than 4MB. The request payload size of each append operation can be a maximum of 4MB.

From REST API documentation:

Append Block uploads a block to the end of an existing append blob.
The block of data is immediately available once the call succeeds on
the server. A block may be up to 4 MiB in size.

Please split your data in such a way that each call to AppendBlockAsync is not uploading data more than 4MB.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading