Azure EventGrid(创建的 Blob)函数输出流
Azure EventGrid (Blob Created) Function output stream
如果我创建一个 azure 函数 Blob 触发器,我可以定义 blob 的输入流和我想写入一些数据的输出流,签名类似于下面。
public async Task RunAsync(
[BlobTrigger(BlobPath, Connection = "FileStorage")]
Stream inputStream,
[Blob(OutputBlobPath, FileAccess.Write, Connection = "FileStorage")]
Stream outputStream,
/* other fields removed for brevity */
)
{
/* ... */
}
是否可以在使用为创建 blob 而触发的 EventGrid 触发器时定义类似的东西?
即
public async Task RunAsync(
[EventGridTrigger] EventGridEvent eventGridEvent,
[Blob("{data.url}", FileAccess.Read, Connection = "FileStorage")] Stream input,
/* is something like this possible -> */ [Blob(?, FileAccess.Write, Connection = "FileStorage")] Stream output)
{
/* ... */
}
可以为 blob 绑定到 CloudBlobContainer 而不是 Stream,这为 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
}
来自Azure docs:
You can bind to the following types to write blobs:
TextWriter
out string
out Byte[]
CloudBlobStream
Stream
CloudBlobContainer
CloudBlobDirectory
ICloudBlob
CloudBlockBlob
CloudPageBlob
CloudAppendBlob
当然你可以在 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);
......
}
如果我创建一个 azure 函数 Blob 触发器,我可以定义 blob 的输入流和我想写入一些数据的输出流,签名类似于下面。
public async Task RunAsync(
[BlobTrigger(BlobPath, Connection = "FileStorage")]
Stream inputStream,
[Blob(OutputBlobPath, FileAccess.Write, Connection = "FileStorage")]
Stream outputStream,
/* other fields removed for brevity */
)
{
/* ... */
}
是否可以在使用为创建 blob 而触发的 EventGrid 触发器时定义类似的东西? 即
public async Task RunAsync(
[EventGridTrigger] EventGridEvent eventGridEvent,
[Blob("{data.url}", FileAccess.Read, Connection = "FileStorage")] Stream input,
/* is something like this possible -> */ [Blob(?, FileAccess.Write, Connection = "FileStorage")] Stream output)
{
/* ... */
}
可以为 blob 绑定到 CloudBlobContainer 而不是 Stream,这为 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
}
来自Azure docs:
You can bind to the following types to write blobs:
TextWriter
out string
out Byte[]
CloudBlobStream
Stream
CloudBlobContainer
CloudBlobDirectory
ICloudBlob
CloudBlockBlob
CloudPageBlob
CloudAppendBlob
当然你可以在 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);
......
}