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?
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.
After you create a snapshot, you can read, copy, or delete it, but you cannot modify it.
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.
As Gaurav also mentioned in his answer, the default behavior of UploadFromStream API is to overwrite if the blob already exists.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With