C# Azure EventGrid(Blob已创建)函数输出流
如果我创建一个azure函数Blob触发器,我可以定义Blob的输入流和我想向其中写入一些数据的输出流,签名如下所示C# Azure EventGrid(Blob已创建)函数输出流,c#,azure-functions,azure-blob-storage,azure-eventgrid,azure-blob-trigger,C#,Azure Functions,Azure Blob Storage,Azure Eventgrid,Azure Blob Trigger,如果我创建一个azure函数Blob触发器,我可以定义Blob的输入流和我想向其中写入一些数据的输出流,签名如下所示 公共异步任务RunAsync( [BlobTrigger(BlobPath,Connection=“FileStorage”)] 流输入流, [Blob(OutputBlobPath,FileAccess.Write,Connection=“FileStorage”)] 流输出流, /*为简洁起见,删除了其他字段*/ ) { /* ... */ } 在使用为创建的blob触
公共异步任务RunAsync(
[BlobTrigger(BlobPath,Connection=“FileStorage”)]
流输入流,
[Blob(OutputBlobPath,FileAccess.Write,Connection=“FileStorage”)]
流输出流,
/*为简洁起见,删除了其他字段*/
)
{
/* ... */
}
在使用为创建的blob触发的EventGrid触发器时,是否可以定义类似的内容?
i、 e
公共异步任务RunAsync(
[EventGridTrigger]EventGridEvent EventGridEvent,
[Blob({data.url}),FileAccess.Read,Connection=“FileStorage”)]流输入,
/*是否可能是这样的->*/[Blob(?,FileAccess.Write,Connection=“FileStorage”)]流输出)
{
/* ... */
}
可以绑定到CloudBlobContainer,而不是blob的流,后者为blob提供完整的存储API。它看起来像这样:
public static async Task Run(
[EventGridTrigger] EventGridEvent eventGridEvent,
[Blob(/* container params */)] CloudBlobContainer blobContainer,
ILogger log)
{
// Use blobContainer to read/write blobs in container
}
从:
当然,您可以在EvenGrid触发器函数中使用输出流。我在本地测试它。首先,我上传了一个名为“input.txt”的blob,内容为“input”。在运行我的函数后,我上传另一个blob(或删除另一个blob)来触发触发器,然后将内容“input”添加到名为“test.txt”的blob中 这是我的密码
[FunctionName("Function1")]
public static async System.Threading.Tasks.Task RunAsync([EventGridTrigger] EventGridEvent eventGridEvent,
[Blob("sample-items/input.txt", FileAccess.Read, Connection = "AzureWebJobsStorage")] Stream input,
[Blob("sample-items/test.txt", FileAccess.Write, Connection = "AzureWebJobsStorage")] Stream output)
{
await input.CopyToAsync(output);
......
}
我最终走上了这条路,我最终使用了CludBlockBlob,并向后工作。这里的问题是我有动态路径,这意味着我必须使用{data.url}作为blob路径。我无法像您那样操作它来更新写入路径。当您使用blob触发器时,您可以使用“a/{b}/”之类的内容定义一个动态url,据我所知,它不适用于EventGridTriggers
[FunctionName("Function1")]
public static async System.Threading.Tasks.Task RunAsync([EventGridTrigger] EventGridEvent eventGridEvent,
[Blob("sample-items/input.txt", FileAccess.Read, Connection = "AzureWebJobsStorage")] Stream input,
[Blob("sample-items/test.txt", FileAccess.Write, Connection = "AzureWebJobsStorage")] Stream output)
{
await input.CopyToAsync(output);
......
}