TransferManager.CopyDirectoryAsync不替换文件 [英] TransferManager.CopyDirectoryAsync is not replacing the files

查看:131
本文介绍了TransferManager.CopyDirectoryAsync不替换文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好团队,

在我们的一个项目中,每次需要将文件复制到输出Blob时,我们都有要求,如果文件已经存在,则需要替换文件

我写了流畅的代码.

    var Container = _blobClient.GetContainerReference(ContainerName);
                CloudBlobDirectory源= Container.GetDirectoryReference(源);
                CloudBlobDirectory dest = Container.GetDirectoryReference(Target);

等待TransferManager.CopyDirectoryAsync(source,dest,true,新的CopyDirectoryOptions {递归= true},新的DirectoryTransferContext());

如果文件不是 在存储区中,但是存储区中已经存在文件,不会替换文件.请在这里提供帮助.

我们正在出于上述目的使用Microsoft.WindowsAzure.Storage.DataMovement库.

也请提出对上述代码的任何改进.

解决方案

下面的代码将比较源代码和目的地,并决定是否应覆盖.看看是否有帮助.

上下文.ShouldOverwriteCallback=(源,目标)=>
{
    var sourceFile = new FileInfo((string)source);
    var destBlob =目标为CloudBlob;
    返回sourceFile.LastWriteTimeUtc> destBlob.Properties.LastModified;
};

参考: https://stackoverflow.com/questions/41043925/azure-uploaddirectoryasync-doesnt-overwrite-existing-files-if-changed

-------------- -------------------------------------------------- ----------------------------------

如果此答案有帮助,点击"标记为答案"或 投票.要提供有关您的论坛体验的其他反馈,请单击 此处


Hi  Team,

In One of our project we have requirment every time we need to copy the files to output blobs,if files are already present then we need replace the  files

I wrote the flowing code. 

   var Container = _blobClient.GetContainerReference(ContainerName);
                CloudBlobDirectory source = Container.GetDirectoryReference(Source);
                CloudBlobDirectory dest = Container.GetDirectoryReference(Target);

await TransferManager.CopyDirectoryAsync(source, dest, true, new CopyDirectoryOptions { Recursive = true }, new DirectoryTransferContext());

This is works fine if files are not  there in the storage ,but files already present in storage ,Its not replacing the files.Could you please help here.

we are using  Microsoft.WindowsAzure.Storage.DataMovement library for above purpose.

And also please suggest any improvement in above code.

解决方案

Code below will compare source and destination and decide if should overwrite or not. See if it helps.

context.ShouldOverwriteCallback = (source, destination) =>
{
    var sourceFile = new FileInfo((string)source);
    var destBlob = destination as CloudBlob;
    return sourceFile.LastWriteTimeUtc > destBlob.Properties.LastModified;
};

Refer: https://stackoverflow.com/questions/41043925/azure-uploaddirectoryasync-doesnt-overwrite-existing-files-if-changed

--------------------------------------------------------------------------------------------------

If this answer was helpful, click "Mark as Answer" or Up-Vote. To provide additional feedback on your forum experience, click here


这篇关于TransferManager.CopyDirectoryAsync不替换文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆