Replace the Contents inside Azure Storage

好久不见. 提交于 2020-07-18 09:24:04

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/22039193/replace-the-contents-inside-azure-storage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!