Azure CloudFile UploadFromFile "The specified resource name contains invalid characters"



我正在尝试上传文件,但收到异常"指定的资源名称包含无效字符"。

我使用的路径是@"C:\Test\Test.txt"。 当我更改为相对寻址(即@".\Test.txt"(并将文件放在exe文件夹中时,它将起作用。

我需要知道的是相对寻址从 .NET 客户端将文件上传到 Azure 文件存储的唯一选项? 有没有办法引用具有完整路径的文件并上传到文件存储?

更新:根据下面的评论和答案,我意识到了我的错误:我向 GetFileReference 方法提供了传入文件路径,其中这应该是 Azure 中新文件的名称,因此它包含无效的":"。 评论是对的,我应该提供代码,可能更容易诊断。

public static async Task WriteFileToStorage(string filePath)
{
    CloudFileShare fileShare = GetCloudFileShare();
    CloudFileDirectory fileDirectory = fileShare.GetRootDirectoryReference();
    CloudFile cloudFile = fileDirectory.GetFileReference(filePath);
    await cloudFile.UploadFromFileAsync(filePath);
}
.

Net 客户端在上传到 Azure 文件存储时确实支持完整路径。

最好提供正在使用的完整代码,包括本地和 Azure 文件存储中的文件名/路径。

这是我测试的代码,它可以工作。(我正在使用软件包WindowsAzure.Storage,版本9.3.3(:

        static void Main(string[] args)
        {
            CloudStorageAccount storageAccount = new CloudStorageAccount(new StorageCredentials("account_name", "account_key"), true);
            CloudFileClient fileClient = storageAccount.CreateCloudFileClient();
            CloudFileShare fileShare = fileClient.GetShareReference("test");
            CloudFileDirectory rootDir = fileShare.GetRootDirectoryReference();
            CloudFile myfile = rootDir.GetFileReference("mytest.txt");
            //the full file path on local
            myfile.UploadFromFile(@"C:TestTest.txt");
}

相关内容

最新更新