【问题标题】:Azure function does not access to Azure files shareAzure 功能无法访问 Azure 文件共享
【发布时间】:2021-12-27 03:18:47
【问题描述】:

我正在尝试从 Azure 函数的共享文件中读取文件。 在本地一切正常,但是当我部署我的测试项目时出现“connectionString”错误。代码很简单:

 string connectionString = Environment.GetEnvironmentVariable("MyStorage", EnvironmentVariableTarget.Process);
        string FileSharedContainer = Environment.GetEnvironmentVariable("MySharedContainer", EnvironmentVariableTarget.Process);
        string InputCloudFolder = Environment.GetEnvironmentVariable("InputCloudFolder", EnvironmentVariableTarget.Process);
        string ProcessedCloudFolder = Environment.GetEnvironmentVariable("ProcessedCloudFolder", EnvironmentVariableTarget.Process);
        CloudStorageAccount cloudStorageAccount = CloudStorageAccount.Parse(connectionString);
        CloudFileClient cloudFileClient = cloudStorageAccount.CreateCloudFileClient();
        CloudFileShare cloudFileShare = cloudFileClient.GetShareReference(FileSharedContainer);
        CloudFileDirectory rootDirectory = cloudFileShare.GetRootDirectoryReference();
        CloudFileDirectory InputfileDirectory = rootDirectory.GetDirectoryReference(InputCloudFolder);
        CloudFileDirectory ProcessedfileDirectory = rootDirectory.GetDirectoryReference(ProcessedCloudFolder);
        List<IListFileItem> fileList = GetAllFilesFromDirectory(InputfileDirectory);
        string fileNames = "";
        foreach (var p in fileList)
        {
            var CurrentFile = (CloudFile)p;
            fileNames += CurrentFile.Name +" ";
        }
        return new OkObjectResult("N. File processed is: " + fileList.Count + ".  Filenames" + fileNames);

这是一个演示 http 触发函数,即使在 Azure 上也可以从共享文件夹返回文件列表。 它在本地机器上运行良好,但在部署环境中失败并出现此错误:

值不能为空。 (参数'connectionString')

请帮帮我....!

【问题讨论】:

标签: azure azure-functions azure-blob-storage


【解决方案1】:

谢谢Anupam Chand。发布您的建议作为答案,以便对面临类似问题的其他社区成员有所帮助。

按照建议,您是否按照下图添加了 mystorage 连接字符串

还尝试调试语句以检查检索值的代码。并尝试使用新版本的 SDK。

dotnet add package Azure.Storage.Files.Shares

更多信息请查看My Storage applicationNuGet Packages

【讨论】:

    猜你喜欢
    • 2019-08-18
    • 2019-07-11
    • 1970-01-01
    • 1970-01-01
    • 2015-04-27
    • 2021-02-18
    • 2022-01-11
    • 2019-05-25
    • 1970-01-01
    相关资源
    最近更新 更多