首页 > 解决方案 > 当我使用 Azure 函数在 Datalake 中上传文件时,存储事件触发器不起作用

问题描述

我创建了一个存储事件触发器来触发 Azure 数据工厂中的管道。当我手动将文件放入数据湖时,此触发器起作用。但是从 Azure Function 上传文件时,触发器不起作用。

以下是我在数据湖中上传文件的功能。

public void UploadFileToDatalake(FileUpload file, string containerSasUri, string stage, string dir, ILogger log)
        {
            log.LogInformation("inside uploadFileTodatalake");
            UriBuilder sasUri = new UriBuilder(containerSasUri);
            DataLakeServiceClient dataLakeServiceClient = new DataLakeServiceClient(sasUri.Uri);

            string container = Globals._transientContainer;
            var fileSystemClient = dataLakeServiceClient.GetFileSystemClient(container);

            string pathFileDL = file.Name;
            
            string directory = dir;

            MemoryStream ms = new MemoryStream();
            StreamWriter sw = new StreamWriter(ms);
            sw.Write(File.ReadAllText(file.FullPath));
            sw.Flush();
            ms.Seek(0, SeekOrigin.Begin);

            file.Content = ms;

            DataLakeDirectoryClient directoryClient = fileSystemClient.GetDirectoryClient(directory);
            try
            {
                if (directoryClient.Exists())
                {
                    log.LogInformation(directoryClient.Name);
                    DataLakeFileClient fileClient = directoryClient.CreateFile(pathFileDL); // 0kb blob
                    file.Content.Position = 0;
                    fileClient.Upload(file.Content, true);
                    log.LogInformation($"{stage}: {file.Name} uploaded to {pathFileDL}");
                    file.Content.Close();
                }
            }
            finally
            {
                //fileSystemClient.Delete();
            }
        }



FileUpload 是我正在使用的模型类。

public class FileUpload
    {
        public string Name { get; set; }
        public Stream Content { get; set; }
        public string FullPath { get; set; }
    }

提前致谢。

标签: c#.netazure-functionsazure-data-factory-2azure-data-lake-gen2

解决方案


我尝试使用博客在 azure blob 中 上传文件azure function

在创建 azure 函数之前,我创建了管道以在新文件到达/存储 blobStorage Event Trigger上创建时触发。

尝试使用手动上传文件azure portal。事件网格触发

在创建并发布了azure functionazure 之后。现在运行 azure 函数。它在存储容器上生成随机文件,并且预期的存储事件触发器也运行。我可以在门户上看到已触发的输出。

在此处输入图像描述


推荐阅读