Azure UploadDirectoryAsync doesn't overwrite existing files if changed

拥有回忆 提交于 2019-12-12 03:42:45

问题


I am doing Directory upload using Microsoft.WindowsAzure.Storage.DataMovement library as below

     TransferManager.Configurations.ParallelOperations = 64;

         UploadDirectoryOptions options = new UploadDirectoryOptions()
                    {                              
                        ContentType = "image/jpeg",
                        Recursive = true,                   

                    };


    context.FileTransferred += FileTransferredCallback;
    context.FileFailed += FileFailedCallback;
    context.FileSkipped += FileSkippedCallback;


    await TransferManager.UploadDirectoryAsync(sourceDir, destDir, options:
 options, context: context, cancellationToken: cts.Token);

I recognized that if I changed the image with the same name, function is ignoring the image and returns exception as file exists. How can I replace the image if datemodified is changed? In the first place of course datemodified on my local pc and azure should be synchronized.


回答1:


I just figured out Microsoft.WindowsAzure.Storage.DataMovement package has a new update and I installed 0.4.1 version. It looks like that it exposes new methods and events. I am not sure if this was available in the version 0.3 (my previous one) but I only figured out after installing version 0.4.1 Microsoft.WindowsAzure.Storage.DataMovement package. Code below will compare source and destination and decide if should overwrite or not. I hope that it helps anyone else having the same issue.

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


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

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