简体   繁体   English

如何使用 .net 核心从不同存储帐户的 Azure 文件共享(不是 blob)复制文件

[英]How to copy files from Azure File-Share (not blob) of different storage account using .net core

public void MoveFiles(AzureFileClient srcAzureClient, AzureFileClient destAzureClient, ShareClient srcShareClient, ShareClient destShareClient, string dirName)
{
    if (!destAzureClient.ShareClient.GetDirectoryClient(dirName).Exists())
        destAzureClient.ShareClient.GetDirectoryClient(dirName).Create();

    var fileItems = GetChildNodes(srcShareClient, dirName);

    if (fileItems.Count == 0)
        return;

    foreach (var item in fileItems)
    {
        if (item.ShareFileItem.IsDirectory)
        {
            MoveFiles(srcAzureClient, destAzureClient, srcShareClient, destShareClient, $"{dirName}/{item.ShareFileItem.Name}");
        }
        else
        {
            var srcFileClient = srcShareClient.GetDirectoryClient(Path.GetDirectoryName(item.FullPath)).GetFileClient(Path.GetFileName(item.FullPath));
            var destFileClient = destShareClient.GetDirectoryClient(Path.GetDirectoryName(item.FullPath)).GetFileClient(Path.GetFileName(item.FullPath)); 

            if (srcFileClient.Exists())
            {
                destFileClient.StartCopy(srcFileClient.Uri);
            }
        }
    }
}

This code is throwing an error at此代码在

destFileClient.StartCopy(srcFileClient.Uri) 

saying

sourceCopy is not verified, connection strings are given to both source & destination fileShare object sourceCopy 未验证,连接字符串提供给源和目标文件共享 object

I am able to copy files from the same account storage.我能够从同一个帐户存储复制文件。

When copying files (or blobs) across storage accounts, the source file (or blob) must be publicly accessible.跨存储帐户复制文件(或 blob)时,源文件(或 blob)必须可公开访问。 This restriction does not apply when the source and destination are in the same storage account.当源和目标位于同一存储帐户中时,此限制不适用。

Because Azure Files are inherently private (there's no concept of ACL like we have in Blob Storage), you are getting this error as Azure Storage Service is not able to read the source file.因为 Azure 文件本质上是私有的(没有像我们在 Blob 存储中那样的 ACL 的概念),您会收到此错误,因为 Azure 存储服务无法读取源文件。

To fix this, you would need to create a SAS URL with at least read permission on the source file and use that SAS URL as copy source. To fix this, you would need to create a SAS URL with at least read permission on the source file and use that SAS URL as copy source.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Powershell:将文件从 Azure 文件共享复制到 Blob 存储帐户 - Powershell: Copy file from Azure File Share to Blob Storage account Azure将Blob复制到不同的高级存储帐户 - Azure Copy blob to different premium storage account 如何在 ASP.NET Core 应用程序中显示来自 Azure Blob 存储帐户的图像? - How to I display an image from my Azure Blob Storage Account in my ASP.NET Core Application? 使用服务帐户从 azure blob 存储中批量删除文件 - Delete files in batch from azure blob storage using service account 如何将大文件上传到 Azure Blob 存储 (.NET Core) - How to upload big files to Azure Blob Storage (.NET Core) 使用.Net API startCopy将页面Blob从一个存储帐户复制到另一个存储帐户 - Copy page blob from one storage account to Another storage account using .Net API startCopy 使用 VB.NET 将所有子目录和文件上传到 Azure 存储帐户文件共享 - Uploading all Sub-Directories and Files to an Azure Storage Account File Share Using VB.NET 使用 Azure Function 从 Azure Blob 存储下载文件返回不同的文件大小 - Downloading files from Azure Blob Storage using Azure Function returns different file size 我可以使用动态文件路径将文件从 Sharepoint 复制到 Azure Blob 存储吗? - Can I copy files from Sharepoint to Azure Blob Storage using dynamic file path? 如何使用位于 azure webapp 中的 .sh 文件将多个文件从本地存储上传到 azure blob 存储 - How to upload multiple files from local storage to the azure blob storage using .sh file that located in azure webapp
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM