简体   繁体   English

如何解决错误:尝试连接 Azure 文件存储时指定的资源名称包含无效字符 Azure Function

[英]How to resolve error:The specified resource name contains invalid characters when trying to connect Azure File Storage in Azure Function

I am trying to conect to Azure File storage using Azure funcitons for this i installed nuget packages such as WindowsAzure.Storage successfullly.我正在尝试使用 Azure 功能连接到 Azure 文件存储,为此我成功安装了 nuget 软件包,例如 WindowsAzure.Storage。

I am trying to connect to the Azure file storage using below set of codes:我正在尝试使用以下代码集连接到 Azure 文件存储:

            var cred = new StorageCredentials("storageaccount", "key");
            var account = new CloudStorageAccount(cred, true);
            CloudFileClient fileClient = account.CreateCloudFileClient();
            CloudFileShare share = fileClient.GetShareReference("reqst");

            CloudFileDirectory rootDir = share.GetRootDirectoryReference();
            CloudFileDirectory sampleDir = rootDir.GetDirectoryReference("Inbox");
            CloudFile file = sampleDir.GetFileReference(FileName);
            await file.DownloadToStreamAsync(memstream);

The issue is the var account = new CloudStorageAccount(cred, true);问题是 var account = new CloudStorageAccount(cred, true); it self it throws exception as The specified resource name contains invalid characters not sure how to solve this everything seems to be correct.它自己抛出异常,因为指定的资源名称包含无效字符,不确定如何解决这个问题,一切似乎都是正确的。 If the error comes while getting file reference then i could assume that i was giving file name incorrectly or location and etc but during connection it self it is throwing error.如果在获取文件引用时出现错误,那么我可以假设我错误地提供了文件名或位置等,但是在连接过程中它自己会抛出错误。

The same code i have tried to write in below format but in the storage account step itself it gives the same error.我尝试以以下格式编写相同的代码,但在存储帐户步骤本身中它给出了相同的错误。

        storageAccount                
   =CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
            fileClient = storageAccount.CreateCloudFileClient();
            share = fileClient.GetShareReference("reqst");
            memstream = new MemoryStream();
            rootDir = share.GetRootDirectoryReference();
            sampleDir = rootDir.GetDirectoryReference("Inbox");
            file = sampleDir.GetFileReference(FileName);
           await file.DownloadToStreamAsync(memstream);

The same code if i write in a separate console application it worked perfectly.如果我在单独的控制台应用程序中编写相同的代码,它可以完美运行。 Not sure why it is not working in Azure Function case only.不知道为什么它仅在 Azure Function 案例中不起作用。

Can any one help me to solve the above error(The specified resource name contains invalid characters) while trying to connect to azure file storage using azure function?在尝试使用 azure function 连接到 azure 文件存储时,谁能帮我解决上述错误(指定的资源名称包含无效字符)?

I have looked into various blogs/posts such as below but it has been given same code as above but it is failing for me:我查看了各种博客/帖子,如下所示,但已给出与上面相同的代码,但对我来说失败了:

Azure Function Status Code 500 internal server error Azure Function 状态代码 500 内部服务器错误

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

Thanks in Advance提前致谢

Regards问候

ChaitanyaNG柴坦阳

Update on May 12-2020 2020 年 5 月 12 日至 2020 年更新

在此处输入图像描述

Thanks for all the help till now.感谢您到现在为止的所有帮助。 I have solved my issue by following the below steps not sure if below is the correct one or the only one or there is another better way present but below steps solved the issue for me:我已经按照以下步骤解决了我的问题,不确定下面是正确的还是唯一的,或者还有另一种更好的方法,但以下步骤为我解决了这个问题:

  1. Updated my Azure Function template which gets displayed while creating new Azure function project from New->Project in VS更新了我的 Azure Function 模板,该模板在创建新 Azure ZC1C425268E683894D14ZA 项目时显示
  2. Then in the version selected Azure Function V3然后在版本中选择 Azure Function V3
  3. Added the above code as is after installing the Storage related package在安装存储相关的 package 后按原样添加上述代码

And it worked without any issues.它没有任何问题。

暂无
暂无

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

相关问题 Microsoft.Azure.StorageException:指定的资源名称包含无效字符 - Microsoft.Azure.StorageException: The specified resource name contains invalid characters Azure CloudFile - “指定的资源名称包含无效字符。” - Azure CloudFile - “The specifed resource name contains invalid characters.” 指定的资源名称包含无效字符 为 blob 生成 SAS url 时出错,即使 blob 名称有效 - The specified resource name contains invalid characters Error generating SAS url for blob even though blob name is valid 指定的资源名称长度不在允许的范围内Azure Blob存储 - The specified resource name length is not within the permissible limits Azure Blob Storage azure blob存储出现错误-指定的资源不存在 - azure blob storage getting error - the specified resource does not exist Azure Blob存储-如何确定指定的容器是否包含任何Blob? - Azure Blob Storage - How to determine if a specified container contains any blobs? Azure function 将文件解压缩到 blob 存储时绑定到容器错误 - Azure function binding to container error when unzipping file to blob storage 尝试将Azure Function应用连接到Azure Cosmos DB表时出现错误400 - Error 400 when trying to Connect Azure Function App to Azure Cosmos DB Table 在Azure本地存储下压缩文件时出错,“目录名称无效” - Error while zipping file under Azure Local Storage “The directory Name is Invalid” Azure 存储表运行时出错 Azure Function - Azure Storage Table Error when running Azure Function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM