Loading...

Troubleshooting “InvalidBlock” Exception during upload operation

Troubleshooting “InvalidBlock” Exception during upload operation

The Put Block operation is used in conjunction with other operations to upload data as blocks to a block blob. This operation is mainly used for uploading large files or data streams in smaller blocks, rather than uploading the entire content in a single request.

 

There can be different types of errors that you might encounter while uploading blobs via Put Block and Put Block List and has been discussed under blog - Troubleshooting InvalidBlock 'The specified block list is invalid’ based errors - Microsoft Community Hub.

 

In this blog, we will mainly focus on how to upload a block blob by PUT Block & PUT Block List APIs using POSTMAN, how to deal with “Invalid Block/Blob 'The specified blob or block content is invalid'” error due to incorrect BlockID and make use of GetBlockList API to identify Uncommitted and Committed blocks.

 

Put Block

This API creates a new block to be committed as part of a blob. Before uploading, each block is given a unique block ID. The block ID is a Base64-encoded string that helps identify each block. Before it's encoded, the string must be less than or equal to 64 bytes in size. For a specified block, the length of the value before encoding, for the block ID parameter must be the same size for each block.

 

Making a Put Block call using POSTMAN

Sample URL: https://<storageaccountname>.blob.core.windows.net/<containername>/<blobpath>?comp=block&blockid=id&SAS

 

Blockid = base64 of any number/string (convert using  url encoding - Search (bing.com))

Here, I have used blockid = base64 of 2 characters e.g. 10.

shailjaT_1-1692266608752.png   shailjaT_0-1692266608750.png

shailjaT_5-1692266697826.png

Add content of the block in the Body section.

shailjaT_6-1692266728738.png

Once you hit the API, you will get response code as 201. This shall confirm that currently the block is in uncommitted state and is ready to be committed to be a part of the blob by PUT Block List API call further.

 

This is the first uncommitted block that we uploaded using PUT Block, so the block ID that we used to upload this block can be any 64 bytes or lesser value that is base64 encoded. Like in this case we used base64 of 10 for uncommitting the first block.

shailjaT_7-1692266757073.png

Now, the next aligned blocks that are to be uploaded should ideally have the blockID that is base64 of any 2-digit character only. If you try to upload a block with blockID other than 2 digits, it will throw the below error-

“400 – The specified blob or block content is invalid.”

 

In the example below, we have used blockID= base64 of 101.

shailjaT_8-1692266792534.png

Therefore, all the blocks should have the block Id of the same length before encoding it to base64 format in order to avoid the above error.

Reference Doc:  Uploading blob or block content fails in Azure Blob Storage - Azure | Microsoft Learn

 

The next is to identify if the blocks are in committed or uncommitted state.

 

Get Block List

The Get Block List operation retrieves the list of blocks that have been uploaded in chunks as part of a block blob. It gives the list of

  • Uncommitted Block List- The list of blocks that have been successfully uploaded for the specified blob by using Put Block but are not committed yet using Put Block List
  • Committed Block List- The list of blocks that have been successfully committed to a specified blob by using Put Block List

Making a Get Block List call using POSTMAN-

Sample URL: https://<storageaccountname>.blob.core.windows.net/<containername>/<blobname>?comp=blocklist&blocklisttype=all&SAS

 

shailjaT_9-1692266816908.png

This shall return the list of committed and uncommitted blocks and you can review the output for different sizes of the blocks. Each block can be of different size but with a max limit on content size. I have uploaded three blocks using PUT Block and the block IDs are – base64 of 10, 11 & 12.

 

shailjaT_10-1692266831457.png

The following table describes the maximum permitted block and blob sizes, by service version:

Service version

Maximum block size (via Put Block)

Maximum blob size (via Put Block List)

Maximum blob size via single write operation (via Put Blob)

Version 2019-12-12 and later

4,000 mebibytes (MiB)

Approximately 190.7 tebibytes (TiB) (4,000 MiB × 50,000 blocks)

5,000 MiB

Versions 2016-05-31 through 2019-07-07

100 MiB

Approximately 4.75 TiB (100 MiB × 50,000 blocks)

256 MiB

Versions earlier than 2016-05-31

4 MiB

Approximately 195 GiB (4 MiB × 50,000 blocks)

64 MiB

Reference Doc: Get Block List (REST API) - Azure Storage | Microsoft Learn

 

Once you have verified the blocks and they appear to be in sync, we can proceed further with the next API to commit the blocks further.

 

Put Block List

This operation is used to commit a list of blocks in a specific order to form or update a block blob. It essentially tells Azure how to arrange the uploaded uncommitted blocks by Put Block to construct the final blob.

 

Making a Put Block List call using POSTMAN-

Sample URL: https://<storageaccountname>.blob.core.windows.net/<containername>/<blobpath>?comp=blocklist&SAS

 

shailjaT_11-1692266877121.png

In the Request Body of the Put Block List method, add the list of BlockIDs, maintaining the order of the blocks.

 

Request Body: 

<?xml version="1.0" encoding="utf-8"?> 

<BlockList> 

  <Latest>BlockID1</Latest> 

  <Latest>BlockID2</Latest> 

  <Latest>BlockID3</Latest> 

</BlockList> 

 

shailjaT_12-1692266890187.png

Reference Doc: Put Block List (REST API) - Azure Storage | Microsoft Learn

 

We can also verify this by again running Get Block List. By blockID we can verify that the block has been successfully committed.

shailjaT_13-1692266903624.png

We can also verify the same from the Azure Portal-

shailjaT_14-1692266918445.png

Please note there is a time limit of nearly 7 days for committing all the blocks into a blob after uploading them. If the Put Block List operation is not performed within this time frame, the uploaded blocks become eligible for garbage collection.

Reference Doc: Uploading blob or block content fails in Azure Blob Storage - Azure | Microsoft Learn

 

Hope this helps!

Published on:

Learn more
Azure PaaS Blog articles
Azure PaaS Blog articles

Azure PaaS Blog articles

Share post:

Related posts

Azure Storage - TLS 1.0 and 1.1 retirement

Overview TLS 1.0 and 1.1 retirement on Azure Storage was previously announced for Nov 1st, 2024, and it was postponed recently to 1 year later...

1 year ago

Efficient Management of Append and Page Blobs Using Azure Storage Actions

  Overview In Azure Storage, Blob Lifecycle Management (BLM) allows you to automate the management of your data based on rules defined by...

1 year ago

[Azure AI Search] Internal Server Error when creating CMK encrypted objects

Scenario Customers follow the Microsoft doc to create CMK encrypted objects (data source, index etc.), but get the 500 Internal Serv...

1 year ago

Optimizing Azure Table Storage: Automated Data Cleanup using a PowerShell script with Azure Automate

Scenario This blog’s aim is to manage Table Storage data efficiently. Imagine you have a large Azure Table Storage that accumulates logs from ...

1 year ago

Optimizing Azure Table Storage: Automated Data Clean-up using a PowerShell script with Azure Automat

Scenario This blog’s aim is to manage Table Storage data efficiently. Imagine you have a large Azure Table Storage that accumulates logs from ...

1 year ago

Restoring Soft-Deleted Blobs with multithreading in Azure Storage Using C#

Blob soft delete is an essential feature that safeguards your data against accidental deletions or overwrites. By retaining deleted data for a...

1 year ago

Performing simple Azure Table Storage REST API operations using curl command.

The blog provides guidance to perform simple Table Storage REST API operations such as Create table, Delete Table, Insert entity, Delete entit...

1 year ago

Bulk delete all the old jobs from the batch account

Deleting a Job also deletes all Tasks that are part of that Job, and all Job statistics. This also overrides the retention period for Task dat...

1 year ago

Utilizing Azure Storage and Runbooks for scheduled automated backups of Azure SQL Databases

In this article, we are going to provide detailed steps to create a scheduled Azure SQL Database backup to storage account using automation. T...

2 years ago

[Azure Service Bus] JMS messages getting dead-lettered

The article discusses a problem where numerous messages end up in the dead letter queue (DLQ) when the JMS service bus consumer connects to th...

2 years ago

Newsletter

Get the latest Dynamics 365 and Power Platform content in your inbox

A curated digest of community blogs, product news, videos, and podcasts — delivered without the noise.

Weekly updates Unsubscribe anytime Fresh community picks
We use your email only for the newsletter and you can unsubscribe at any time.
By subscribing, you agree to the privacy policy.