Azure CloudFile-“指定的资源名称包含无效字符." [英] Azure CloudFile - "The specifed resource name contains invalid characters."

查看:157
本文介绍了Azure CloudFile-“指定的资源名称包含无效字符."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将文件从 Azure File Storage 下载到本地文件并获取此异常:

I'm trying to download a file from Azure File Storage to a local file and get this exception:

指定的资源名称包含无效字符."

"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 参数是一个字符串,值是这样的:

The saveTo argument is a string and the value is something like this:

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

saveFrom 参数是这样的:

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

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

I'm creating the argument using this function:

var saveTo = Path.GetTempFileName();

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

What am I doing wrong? I don't have much experience with Azure.

推荐答案

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

The problem is with your saveFrom variable. It should only contain the name of the file and not the whole URL. So if the file you're trying to download is tmpA2DA.tmp, your code should be:

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

请进行此更改,然后重试.应该可以.

Please make this change and try again. It should work.

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

Here's the complete code I used to test:

    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);
            }
        }
    }

这篇关于Azure CloudFile-“指定的资源名称包含无效字符."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆