Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace the Contents inside Azure Storage

Is there are any way to replace a file if the same name exists? I can't see any replace method in Azure Storage. Here is my code:

var client = new CloudBlobClient(
      new Uri(" http://sweetapp.blob.core.windows.net/"), credentials);
var container = client.GetContainerReference("cakepictures");
await container.CreateIfNotExistsAsync();
var perm = new BlobContainerPermissions();
perm.PublicAccess = BlobContainerPublicAccessType.Blob;
await container.SetPermissionsAsync(perm);
var blockBlob = container.GetBlockBlobReference(newfilename + i + file.FileType);
using (var fileStream = await file.OpenSequentialReadAsync())
{
    await blockBlob.UploadFromStreamAsync(fileStream);
}

Is there anything that I could add into this code so that it replaces existing or same file name?

like image 415
hack.luminence Avatar asked Feb 26 '14 10:02

hack.luminence


People also ask

How do I replace a file in BLOB storage?

If a blob exists in blob storage and if you upload another file with the same name as that of the blob, old blob contents will automatically be replaced with the contents of new file. You don't have to do anything special.

Would it be possible to modify an existing blob snapshot?

After you create a snapshot, you can read, copy, or delete it, but you cannot modify it.


2 Answers

If a blob exists in blob storage and if you upload another file with the same name as that of the blob, old blob contents will automatically be replaced with the contents of new file. You don't have to do anything special.

like image 155
Gaurav Mantri Avatar answered Oct 12 '22 02:10

Gaurav Mantri


As Gaurav also mentioned in his answer, the default behavior of UploadFromStream API is to overwrite if the blob already exists.

like image 28
Serdar Ozler Avatar answered Oct 12 '22 00:10

Serdar Ozler