How to resolve error:The specified resource name contains invalid characters when trying to connect Azure File Storage in Azure Function
How to resolve error:The specified resource name contains invalid characters when trying to connect Azure File Storage in Azure Function
我正在尝试使用 Azure 功能连接到 Azure 文件存储,为此我成功安装了 nuget 包,例如 WindowsAzure.Storage。
我正在尝试使用以下一组代码连接到 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);
问题是 var account = new CloudStorageAccount(cred, true);它自己抛出异常,因为指定的资源名称包含无效字符不确定如何解决这个问题一切似乎都是正确的。如果在获取文件引用时出现错误,那么我可以假设我提供的文件名或位置等不正确,但在连接过程中它自己会抛出错误。
我尝试以下面的格式编写相同的代码,但在存储帐户步骤本身中它给出了相同的错误。
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);
如果我在单独的控制台应用程序中编写相同的代码,它会完美运行。不确定为什么它仅在 Azure Function 案例中不起作用。
任何人都可以帮助我解决在尝试使用 azure 函数连接到 azure 文件存储时出现的上述错误(指定的资源名称包含无效字符)吗?
我已经研究了各种 blogs/posts 如下所示,但它已经给出了与上面相同的代码,但它对我来说失败了:
提前致谢
此致
ChaitanyaNG
2020 年 5 月 12 日更新
感谢迄今为止的所有帮助。我已经按照以下步骤解决了我的问题,不确定下面是正确的还是唯一的,或者是否存在另一种更好的方法,但以下步骤为我解决了问题:
- 更新了我的 Azure Function 模板,该模板在从 VS 中的新建-> 项目创建新的 Azure 函数项目时显示
- 然后在版本中选择Azure Function V3
- 安装存储相关包后按原样添加上述代码
而且它没有任何问题。
我正在尝试使用 Azure 功能连接到 Azure 文件存储,为此我成功安装了 nuget 包,例如 WindowsAzure.Storage。
我正在尝试使用以下一组代码连接到 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);
问题是 var account = new CloudStorageAccount(cred, true);它自己抛出异常,因为指定的资源名称包含无效字符不确定如何解决这个问题一切似乎都是正确的。如果在获取文件引用时出现错误,那么我可以假设我提供的文件名或位置等不正确,但在连接过程中它自己会抛出错误。
我尝试以下面的格式编写相同的代码,但在存储帐户步骤本身中它给出了相同的错误。
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);
如果我在单独的控制台应用程序中编写相同的代码,它会完美运行。不确定为什么它仅在 Azure Function 案例中不起作用。
任何人都可以帮助我解决在尝试使用 azure 函数连接到 azure 文件存储时出现的上述错误(指定的资源名称包含无效字符)吗?
我已经研究了各种 blogs/posts 如下所示,但它已经给出了与上面相同的代码,但它对我来说失败了:
提前致谢
此致
ChaitanyaNG
2020 年 5 月 12 日更新
感谢迄今为止的所有帮助。我已经按照以下步骤解决了我的问题,不确定下面是正确的还是唯一的,或者是否存在另一种更好的方法,但以下步骤为我解决了问题:
- 更新了我的 Azure Function 模板,该模板在从 VS 中的新建-> 项目创建新的 Azure 函数项目时显示
- 然后在版本中选择Azure Function V3
- 安装存储相关包后按原样添加上述代码
而且它没有任何问题。