Reputation: 3281
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)
{
}
Upvotes: 0
Views: 2426
Reputation: 2110
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();
}
Upvotes: 3