Reputation: 483
I have an Azure Function which is triggered whenever an image is uploaded to a container in a Azure storage account. I read the stream and do some actions.
I would also like to get the uri of the blob that is triggering the Function but how would I do this? Do I have to work with additional inputs / outputs?
public static void Run(Stream myBlob, TraceWriter log)
{
//get byte array of the stream
byte[] image = ReadStream(myBlob);
// ...
}
Upvotes: 1
Views: 3696
Reputation: 43183
If you really want the full URI, as opposed to just the blob relative path (which string blobTrigger
would give you), you'll need to do something like this:
public static void Run(CloudBlockBlob myBlob, TraceWriter log)
{
// ...
}
At that point, you can use the CloudBlockBlob object model both to get the URI (e.g. StorageUri
or some other related props) and to get the stream (e.g. BeginDownloadToStream
). Note that when you do this, you can no longer directly receive the Stream as an input param.
Upvotes: 4
Reputation: 9881
Based on the webjobs' documentation for blobs, you can simply add a string blobTrigger
parameter:
public static void Run(Stream myBlob, string blobTrigger, TraceWriter log)
Upvotes: 2
Reputation: 35124
In your binding, you can define a variable name for blob path:
"path": "foo/{name}.bar",
Then add name
as another function parameter:
public static void Run(Stream myBlob, string name, TraceWriter log)
Upvotes: 1