Upload Block Blob to Blob Store Failed. Details: Status Code = 400
If y'all're uploading blobs past splitting blobs into blocks and you lot get the error – The specified hulk or block content is invalid , then this post is for you.
Short Version
If you're uploading blobs by splitting blobs into blocks and you become the in a higher place mentioned error, ensure that your block ids of your blocks are of same length. If the block ids of your blocks are of different length, yous'll get this fault.
Long Version
At present for the longer version of this post . A few days back I was working with storage customer library particularly around uploading blobs in chunks and with one detail blob I was constantly getting the error – The specified blob or block content is invalid . I tried numerous combinations even resorting to Balance API direct but to no avail. It but happened with merely one blob. Furthermore if I uploaded the same blob without splitting information technology into blocks, all was well. I was at my wits' finish. Tried searching the Internet for this error but could not notice a conclusive answer to my problem.
Later much trial and error, I was able to simulate the same trouble on other blobs also. Here's how you can recreate it:
- Start uploading the blob past splitting it into blocks. For cake id, permit's do a vii graphic symbol long string e.one thousand. intValue.ToString("d7"). This will ensure that my block ids would be "0000001", "0000002", …, "0000010" …..
- Subsequently one or two blocks are uploaded, abolish the operation.
- Now re-upload the hulk by splitting it into blocks. However this time for block id, let's do a 6 character long string e.g. intValue.ToString("d6").
- You'll get the error as shortly as y'all try to upload the 1st block.
Possible Solutions
Now that we know the root cause of this trouble, let'southward wait at some of the possible solutions to solve this problem.
Wait out
I possible solution is to look out. I know its lame but still a possible solution. We know that Windows Azure Blob Storage Service keeps all uncommitted blocks for a duration of 7 days and if within seven days those uncommitted blocks are not committed, the storage service purges them.
I wish storage service provided some mechanism to purge uncommitted blocks programmatically.
Commit uncommitted blocks
You could peradventure commit the blocks which are in uncommitted state so that at to the lowest degree you get a blob (which would not be the blob nosotros wanted to upload in the first place). You can so delete that blob and re-upload the blob by specifying cake ids which are of aforementioned length. To fetch the list of uncommitted blocks, if you lot're using REST API straight you tin can perform "Get Block List" operation and pass "blocklisttype=uncommitted" equally 1 of the query string parameters. If y'all're using storage client library (assuming you're using the version ii.x of .Net storage client library), you lot can do something like the code below:
private static List<string> GetUncommittedBlockIds(CloudBlockBlob blob) { var sasUri = blob.GetSharedAccessSignature(new SharedAccessBlobPolicy() { SharedAccessExpiryTime = DateTime.UtcNow.AddMinutes(5), Permissions = SharedAccessBlobPermissions.Read, }); var blobUri = new Uri(string.Format("{0}{1}", blob.Uri, sasUri)); List<string> uncommittedBlockIds = new List<string>(); var asking = BlobHttpWebRequestFactory.GetBlockList(blobUri, null, null, BlockListingFilter.Uncommitted, zilch, zippo); //asking.Headers.Add("Authorisation", using (var resp = (HttpWebResponse)request.GetResponse()) { using (var stream = resp.GetResponseStream()) { var getBlockListResponse = new GetBlockListResponse(stream); var blocks = getBlockListResponse.Blocks; foreach (var cake in blocks.Where(b => !b.Committed)) { uncommittedBlockIds.Add(Encoding.UTF8.GetString(Convert.FromBase64String(block.Name))); } } } return uncommittedBlockIds; }
A few things to proceed in mind hither:
- Microsoft.WindowsAzure.Storage.Blob namespace does not have the capability to get the list of uncommitted blocks. You would need to make use of Microsoft.WindowsAzure.Storage.Hulk.Protocol namespace.
- Because we're kind of invoking the REST API past executing an HttpWebRequest, I created a shared access signature on the blob so that I don't have to create "Authorization" header.
Fetch uncommitted blocks to see block id length
You could fetch the list of uncommitted blocks just to find out the length of the block id used. You could then use that block id length for your new upload session and do the upload. Delight see the code snippet higher up to detect this information.
Upload another hulk with same proper name without splitting it into blocks
Yous could also upload some other blob with the same proper name without splitting it into blocks. Information technology could very well be a zero byte blob. That way your uncommitted block list volition be wiped make clean. So you could delete that dummy blob and re-upload the actual hulk.
A Few Words About Blocks
Since we're talking about blocks, I thought it might be useful to mention a few points nearly them:
- Blocks and block related operations are only applicative for "Cake Blobs". Duh!! You'll get an error if you're trying to do these operations on a "Page Blob".
- For uploading large blobs, it is recommended that you dissever your hulk into blocks. In fact if your blob size is more 64 MB, and so you have to split it into blocks.
- Minimum size of a block is 1 Byte and the maximum size of a block is 4 MB. Information technology is recommended that y'all cull a cake size based on your internet connectivity and number of parallel threads you want use to upload these blocks.
- A blob can exist split into a maximum of 50000 blocks. It'south important to remember this limitation because you are reminded of this limit when you're trying to upload 50001st block.
- The length of all the block ids must exist aforementioned. And so if y'all're using an integer value to denote cake id, you make sure that you pad that integer value with "0" so that y'all get aforementioned length. So you could do something similar int.ToString("d6").
- When passing the block id as a parameter, it must be Base64 encoded.
- While the order in which the blocks are uploaded is not of import, the order is of import when you lot commit the cake list because that'south when the blob is constructed by the service. For example, permit'due south say you're uploading a blob by splitting it into 5 blocks (with ids "000001", "000002", "000003", "000004", and "000005"). You could upload these blocks in any club – 000004, 000001, 000003, 000005, 000002 withal when you lot commit the cake list, ensure that the cake ids are passed in proper guild i.e. 000001, 000002, 000003, 000004, 000005.
Summary
That'due south it for this postal service. I hope you've found this information useful. I spent considerable amount of time trying to prepare this problem so I hope it will help some folks out. Every bit e'er, if yous observe any issues with the postal service please let me know and I'll ready it ASAP.
Happy Coding!
Source: https://gauravmantri.com/2013/05/18/windows-azure-blob-storage-dealing-with-the-specified-blob-or-block-content-is-invalid-error/
0 Response to "Upload Block Blob to Blob Store Failed. Details: Status Code = 400"
Postar um comentário