Search code examples
azure-storageazure-blob-storageput

How to delete uncommitted blocks in Azure Blob Storage?


I am trying to do some automation using PUT Block in Azure Blob Storage.

My questions are:

Q1. Do uncommitted blocks reserve space?

Q2. How can I delete the uncommitted blocks?

  • The method I am using now is to get all the uncommitted blocks by GET Block List.
  • Commit the uncommitted blocks using PUT Block List and then delete the blob altogether to free up space.

Is there any better way of deleting uncommitted blocks?


Solution

  • Is there any better way of deleting uncommitted blocks?

    As such there's no direct way of deleting uncommitted blocks. If you do not do anything with those blocks, they are automatically deleted after 7 days.

    One possible solution would be to call Put Block List with empty or a single uncommitted block and then delete the blob. That way all uncommitted blocks will be deleted.

    Other option would be to create another blob with the same name using Put Blob operation. Since your intention is to delete uncommitted blocks, you can create this blob as a zero byte blob.