1

如果我创建一个 azure 函数 Blob Trigger,我可以定义 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 触发器时是否可以定义类似的内容?IE

  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)
        {
            /* ... */
        }
4

2 回答 2

3

可以绑定到 CloudBlobContainer 而不是 blob 的 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 文档

You can bind to the following types to write blobs:

TextWriter
out string
out Byte[]
CloudBlobStream
Stream
CloudBlobContainer
CloudBlobDirectory
ICloudBlob
CloudBlockBlob
CloudPageBlob
CloudAppendBlob
于 2020-07-28T01:59:35.070 回答
0

当然你可以在 EvenGrid 触发函数中使用输出流。我在本地测试它。首先,我上传了一个名为“input.txt”的blob,内容为“input”。运行我的函数后,我上传另一个 blob(或删除另一个 blob)以触发触发器,然后将内容“输入”添加到名为“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);
                    ......
         }
于 2020-07-29T05:48:28.353 回答