0
votes

I am in a situation where i have 1000's of blobs in azure storage which are pictures with url having space in it which is a problem. so as a measure we want to update blob uri and remove spaces in each of them which has one. I know how to get blobs or would figure out but not able to understand how can i update the uri once i get a blob here is my current code to get blobs.

        CloudBlobContainer container = GetContainerReference('containername');
        var blobs=container.ListBlobs().Select(p=>p.Uri.ToString().Contains(' '));
        foreach (CloudBlob item in blobs)
        {

        }
1
Assuming it can be done, wouldn't just removing the space from the blob's name (or URI) make your blob inaccessible? The blob stored in blob storage has a space in its name/URI? - Gaurav Mantri
uri.i agree. probably deleting and creating copy of it is the solution.. - Mandar Jogalekar

1 Answers

2
votes

The Windows Azure BlobStorage API does not provide a method that allows you to change a blob's URI directly. However you still can copy the blob to a new one which has no spaces in its URI and then delete the old one.

CloudBlobContainer container = GetContainerReference('containername');
var blobs = container.ListBlobs().Select(p => p.Uri.ToString().Contains(' '));
foreach (CloudBlob oldBlob in blobs)
{
    var newBlobName = oldBlob.Name.Replace(" ", String.Empty);
    var newBlob = container.GetBlobReference(newBlobName);
    newBlob.CopyFromBlob(oldBlob);

    oldBlob.Delete();
}