If I create an azure function Blob Trigger, I can define the both an input stream of the blob, and an output stream to which I would like to write some data, the signature being similar to below.
public async Task RunAsync(
[BlobTrigger(BlobPath, Connection = "FileStorage")]
Stream inputStream,
[Blob(OutputBlobPath, FileAccess.Write, Connection = "FileStorage")]
Stream outputStream,
/* other fields removed for brevity */
)
{
/* ... */
}
Is it possible to define something similar when using an EventGrid trigger that fires for blob being created? 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)
{
/* ... */
}
It's possible to bind to a CloudBlobContainer rather than a Stream for a blob, which provides the full storage API for blobs. It would look something like this:
public static async Task Run(
[EventGridTrigger] EventGridEvent eventGridEvent,
[Blob(/* container params */)] CloudBlobContainer blobContainer,
ILogger log)
{
// Use blobContainer to read/write blobs in container
}
From the 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
of course you can use output stream in EvenGrid Trigger Function. I test it locally. Firstly, I upload a blob named "input.txt" with the content "input". After run my function, I upload another blob (or delete another blob) to fire the trigger, then the content "input" is added to the blob named "test.txt".
Here is my code.
[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);
......
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.