简体   繁体   中英

How long can an Azure Blob Container Name be?

I have read that azure blob storage container names must be a maximum of 63 characters long (see https://docs.microsoft.com/en-us/rest/api/storageservices/fileservices/naming-and-referencing-containers--blobs--and-metadata ), but before reading this, I was testing container names longer than this, so tried something much longer:

        CloudStorageAccount storageAccount = CloudStorageAccount.Parse("YourKey");
        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
        CloudBlobContainer container = blobClient.GetContainerReference(@"mystorage\A2345678901234567890B234567890C2345678901234567890D234567890E234567890F23456789G234567890\AA345678901234567890B234567890C2345678901234567890D234567890E234567890F23456789G234567890");
        CloudBlockBlob blockBlob = container.GetBlockBlobReference(@"blob.txt");

This seems to work fine (note upper case letters, also supposedly not allowed). I have also used Microsoft Azure Storage Explorer (v0.8.9) to open folders and files created using C# and to create more long folder names (mixed case) in my blob storage.

In real life, I was thinking of having containers up to about 100 characters (replicating a Windows file structure with five levels of folder with subfolder names up to 20 characters. If necessary, I could force these to lower case. Most of what I have read seems to suggest blob storage is better than file storage unless dealing with legacy systems or needing SMB. Based on this reasoning, blob storage sounds the better option, and everything seems to work fine when testing. However, might Microsoft suddenly impose lower case only and the 63 character limit? Is there something else I am missing?

So the maximum length of the container name can be 63 characters. The reason you're not getting any error in your code is because this limit is enforced on the server side. When you create an instance of a CloudBlobContainer using the code:

CloudBlobContainer container = blobClient.GetContainerReference(@"mystorage\A2345678901234567890B234567890C2345678901234567890D234567890E234567890F23456789G234567890\AA345678901234567890B234567890C2345678901234567890D234567890E234567890F23456789G234567890");

This is happening on the client side. If you try to perform any server side operation on this container object (like creating that container), you will get an error because you're violating this 63 characters limit.

You can think of a container as a top-level folder inside your blob storage account. To make an analogy, if you think C:\\ on your computer as storage account, than the container could be windows . Now each container can have zero or more blobs and to create an illusion of hierarchy, you would name your blobs like cursors\\aero_arrow.cur . When naming the blobs, you can have more characters than 63. However since each blob is accessible via a URL ( https://accountname.blob.core.windows.net/containername/blobname ), the max length is restricted by the max characters in a URL which I believe is 1024 characters.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM