How to rename the container name in windows azure?

后端 未结 5 2433
北海茫月
北海茫月 2021-02-19 17:08

Is there any way by which we can rename the blob container name in windows azure ?

相关标签:
5条回答
  • 2021-02-19 17:19

    No. You can't rename a blob container in Windows Azure.

    Code to copy from the old storage to the new storage

    AzCopy /Source:https://oldstorage.blob.core.windows.net/oldstorage /Dest:https://newstorage.blob.core.windows.net/newstorage /SourceKey:sourcekey /DestKey:destkey /S /XO

    0 讨论(0)
  • 2021-02-19 17:22

    Now, you can rename containers with Microsoft's "Microsoft Azure Storage Explorer" (after version 0.8.3). You can also rename azure tables and file shares with this tool. See the release notes here.

    Note that this feature has the following disclaimer during usage.

    Renaming works by copying to the new name, then deleting the source item. Renaming a blob container currently loses the container's properties and metadata, and may take a while if there are lots of blobs.

    Therefore this is not an actual renaming behind the scenes and incurs read/write/transaction costs.

    0 讨论(0)
  • 2021-02-19 17:24

    I couldn't find the rename functionality in the storage explorer v1.15.1 but I did use the clone option to create a copy and delete the old container.

    0 讨论(0)
  • 2021-02-19 17:33

    This RenameBlob method will allow you to rename folders or files in an Azure container.

    • album1/image1.jpg -> album2/image1.jpg
    • album1/image1.jpg -> album1/image2.jpg

    HTH

    public class AzureStorageService
    {
        readonly CloudStorageAccount _storageAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["StorageConnectionString"].ConnectionString);
    
        public void RenameBlob(string oldName, string newName)
        {
            var blobClient = _storageAccount.CreateCloudBlobClient();
            var container = blobClient.GetContainerReference("MyContainer");
    
            var blobs = container.GetDirectoryReference(oldName).ListBlobs();
    
            foreach (var item in blobs)
            {
                string blobUri = item.Uri.ToString();
    
                var oldBlob = container.GetBlockBlobReference(blobUri);
                var newBlob = container.GetBlockBlobReference(blobUri.Replace(oldName, newName));
    
                newBlob.StartCopyFromBlob(oldBlob);
    
               oldBlob.Delete();
            }
        }
    }
    
    0 讨论(0)
  • 2021-02-19 17:44

    UPDATE

    Please see answer from Nuri Tasdemir below.


    No. You can't rename a blob container in Windows Azure. What you could do is create a new blob container with the new name and copy blobs from old blob container to the new one. Once the blobs are copied, you can delete the old blob container. Please note that if you're doing the copy blob in Cloud, this operation is asynchronous. So ensure that the blobs are copied completely before deleting the blob container.

    0 讨论(0)
提交回复
热议问题