Is there any way by which we can rename the blob container name in windows azure ?
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.
This answer is not valid any more. It seems they removed this feature from "Microsoft Azure Storage Explorer"
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.
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.
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.
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
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();
}
}
}
StartCopyFromBlob
doesn't mean the operation completed. –
Selfsupporting © 2022 - 2024 — McMap. All rights reserved.