0
votes

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

enter image description here

1
Please check your account name and account key value.Gaurav Mantri
@GauravMantri-AIS : Already checked those, as i tried to explain if i am running the same code without any change as is individually in a separate console app it is working. That is why i had to post this query.Chaitanya N G
Is there anyway you can print cred variable somehow? Please obfuscate the account name and key by replacing only some of the characters there.Gaurav Mantri
I just tested this code in Azure function, didn't reproduce your issue.Tony Ju
@TonyJu : I am not sure this will make to repro at you side but i think i have left out a piece of information in my original post : 1. It is a HTTP Trigger Azure Function 2. My Packages are updated which screenshot can be found in updated original post 3. It is not working for me in locally itself lastly, thanks for your helpChaitanya N G

1 Answers

1
votes

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
  2. Then in the version selected Azure Function V3
  3. Added the above code as is after installing the Storage related package

And it worked without any issues.