gpt4 book ai didi

c# - Azure 云文件 - "The specifed resource name contains invalid characters."

转载 作者:行者123 更新时间:2023-11-30 16:43:31 25 4
gpt4 key购买 nike

我尝试将文件从 Azure 文件存储 下载到本地文件并出现此异常:

"The specifed resource name contains invalid characters."

代码如下:

if (_cloudFileShare.Exists())
{
CloudFileDirectory rootDir = _cloudFileShare.GetRootDirectoryReference();
CloudFileDirectory tempDir = rootDir.GetDirectoryReference("temp");
if (tempDir.Exists())
{
var file = tempDir.GetFileReference(saveFrom);
file.DownloadToFile(saveTo, FileMode.Open);// OFFENDING LINE
}
}

saveTo 参数是一个字符串,其值如下所示:

"C:\Users\Me\AppData\Local\Temp\tmpF2AD.tmp"

saveFrom 参数是这样的:

https://storageaccount.file.core.windows.net:443/fileshare/temp/tmpA2DA.tmp

我正在使用此函数创建参数:

var saveTo = Path.GetTempFileName();

我做错了什么?我对 Azure 没有太多经验。

最佳答案

问题出在您的 saveFrom 变量上。它应该只包含文件名而不是整个 URL。因此,如果您尝试下载的文件是 tmpA2DA.tmp,您的代码应该是:

var file = tempDir.GetFileReference("tmpA2DA.tmp");

请进行此更改并重试。它应该可以工作。

这是我用来测试的完整代码:

    static void FileDownloadTest()
{
var cred = new StorageCredentials(accountName, accountKey);
var account = new CloudStorageAccount(cred, true);
var client = account.CreateCloudFileClient();
var _cloudFileShare = client.GetShareReference("fileshare");
if (_cloudFileShare.Exists())
{
CloudFileDirectory rootDir = _cloudFileShare.GetRootDirectoryReference();
CloudFileDirectory tempDir = rootDir.GetDirectoryReference("temp");
if (tempDir.Exists())
{
var saveTo = System.IO.Path.GetTempFileName();
var file = tempDir.GetFileReference("tmpA2DA.tmp");
file.DownloadToFile(saveTo, FileMode.Open);
}
}
}

关于c# - Azure 云文件 - "The specifed resource name contains invalid characters.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44849971/

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