[英]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:
我已经按照以下步骤解决了我的问题,不确定下面是正确的还是唯一的,或者还有另一种更好的方法,但以下步骤为我解决了这个问题:
And it worked without any issues.它没有任何问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.