简体   繁体   中英

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.

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

在此处输入图像描述

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM