Reputation: 524
I am trying to conect to Azure File storage using Azure funcitons for this i installed nuget packages such as WindowsAzure.Storage successfullly.
I am trying to connect to the Azure file storage using below set of codes:
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); 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.
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?
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 CloudFile - "The specifed resource name contains invalid characters."
Thanks in Advance
Regards
ChaitanyaNG
Update on May 12-2020
Upvotes: 0
Views: 5244
Reputation: 524
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.
Upvotes: 2