c# - 当我使用 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; }
}
提前致谢。
解决方案
我尝试使用博客在 azure blob 中 上传文件azure function
。
在创建 azure 函数之前,我创建了管道以在新文件到达/在存储 blobStorage Event Trigger
上创建时触发。
尝试使用手动上传文件azure portal
。事件网格触发。
在创建并发布了azure function
azure 之后。现在运行 azure 函数。它在存储容器上生成随机文件,并且预期的存储事件触发器也运行。我可以在门户上看到已触发的输出。
推荐阅读
- android - 所有 api 的 MenuItem 色调 - api > 26 的 iconTint -
- json - 如何从我的下拉列表中检索用户选择的选项?
- python - 我被 Levenshtein 困住了。它一直说“没有名为'Levenshtein'的模块。我已经安装了Levenshtein。我该怎么办?
- gradle - 我如何才能在 intelliJ 中使用 gradle 进行黄瓜报告?
- android - 如何在 Android 中增加 TextView
- javascript - 注销后重定向到相同的url
- python - 同时生成许多 matplotlib 图形
- c# - 如果窗口在后台,如何允许按钮单击事件
- blockchain - 无法挖掘 PoS + mn 硬币的创世块
- c++ - 在不破坏 C++ 抽象的情况下处理对存储在私有映射中的值的封装访问的标准方法