I've created an Azure function with a blob storage trigger - I want to process a file and then dump the file out to another blob storage container.
In the simplest case I suppose it would look like this:
public static void Run(Stream blob, string name, out Stream outputBlob, TraceWriter log)
{
outputBlob = blob;
}
These are my bindings:
{
"bindings": [
{
"name": "blob",
"type": "blobTrigger",
"direction": "in",
"path": "input/{name}",
"connection": "wlimportstaging_STORAGE"
},
{
"name": "outputBlob",
"type": "blob",
"direction": "out",
"path": "original/{name}",
"connection": "wlimportstaging_STORAGE"
}
],
"disabled": false
}
I've read from the documentation that if you return a POCO it will serialize it as JSON.
https://learn.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob#output-usage
This seems to suggest you can output to a stream - I just seem to be getting:
Microsoft.Azure.WebJobs.Host: Can't bind Blob to type 'System.IO.Stream&
Please assist!
You an also do
public static async Task Run(Stream myBlob, string name, Stream outputBlob, TraceWriter log)
{
await myBlob.CopyToAsync(outputBlob);
}
This worked fine. If there is a better approach I would be really interested.
public static async Task Run(Stream blob, string name, Stream outBlob, TraceWriter log)
{
using (MemoryStream ms = new MemoryStream())
{
blob.CopyTo(ms);
var byteArray = ms.ToArray();
await outBlob.WriteAsync(byteArray, 0, byteArray.Length);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With