gpt4 book ai didi

c# - 如何修复在同一存储帐户内将数据从 blob 发送到文件共享的问题?

转载 作者:行者123 更新时间:2023-12-03 07:02:53 24 4
gpt4 key购买 nike

我正在尝试将数据从 Blob 容器发送到文件共享,这是我正在使用的代码,但令人惊讶的是它不起作用:

public static void MoveFileBlobToFileShare(string shareName, string fileName, string sourceDirName, string destinationDirName, string container, string destinationFileName = "")
{
var blobServiceClient = Zeus.AzureStorage.Common.CreateblobServiceClient();
var containerClient = blobServiceClient.GetBlobContainerClient(container);
var blobClient = containerClient.GetBlobClient(sourceDirName + "/" + fileName);
var fileSas = blobClient.GenerateSasUri(Azure.Storage.Sas.BlobSasPermissions.Read, DateTime.UtcNow.AddHours(24));
var shareClient = Common.CreateSMBClientFromConnectionString(shareName);
ShareDirectoryClient directory = shareClient.GetDirectoryClient(destinationDirName);
ShareFileClient file = string.Equals(string.Empty, destinationFileName) ?
directory.GetFileClient(fileName) : directory.GetFileClient(destinationFileName);
file.StartCopy(fileSas);
blobClient.Delete();
}

有没有办法只使用blobClient.URI并摆脱fileSAS

我收到错误:

The specified blob does not exist.
RequestId:b19857e0-001a-0008-670a-5a8332000000
Time:2022-04-27T07:46:55.4219904Z
Status: 404 (The specified blob does not exist.)
ErrorCode: CannotVerifyCopySource

Content:
<?xml version="1.0" encoding="utf-8"?><Error><Code>CannotVerifyCopySource</Code><Message>The specified blob does not exist.
RequestId:b19857e0-001a-0008-670a-5a8332000000
Time:2022-04-27T07:46:55.4219904Z</Message></Error>

Headers:
x-ms-request-id: b19857e0-001a-0008-670a-5a8332000000
x-ms-client-request-id: 697e573f-1ef0-47e5-971e-97f67b4fa083
x-ms-version: 2021-04-10
x-ms-error-code: CannotVerifyCopySource
Content-Length: 225
Content-Type: application/xml
Date: Wed, 27 Apr 2022 07:46:55 GMT
Server: Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0

最佳答案

问题是您开始复制操作但没有等待它完成。相反,您删除作为复制操作的源文件

file.StartCopy(fileSas);

此调用启动复制操作。它在后台运行。它返回 ShareFileCopyInfo您可以检查实例以查看操作的状态。属性 CopyStatus 是一个枚举,其值为 Aborted、Failed、Pending 和 Success,请参阅 the docs .

我怀疑在您的情况下,当您调用 blobClient.Delete(); 时,操作仍处于挂起状态。

根据the official example您可以执行此操作以等待复制操作完成:

        // Start the copy operation
file.StartCopy(fileSas);

if (await file.ExistsAsync())
{
Console.WriteLine($"{sourceFile.Uri} copied to {destFile.Uri}");
}

另一个选项是轮询是否完成。

关于c# - 如何修复在同一存储帐户内将数据从 blob 发送到文件共享的问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72023903/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com