Skip to content

Instantly share code, notes, and snippets.

@markheath markheath/function.json
Last active Nov 21, 2016

Embed
What would you like to do?
F# Blob Bindings with Azure Functions
{
"bindings": [
{
"name": "inputBlob",
"type": "blobTrigger",
"direction": "in",
"path": "samples-workitems/input/{name}",
"connection": "AzureWebJobsDashboard"
},
{
"type": "blob",
"name": "output1",
"path": "samples-workitems/output1/{name}",
"connection": "AzureWebJobsDashboard",
"direction": "out"
},
{
"type": "blob",
"name": "output2",
"path": "samples-workitems/output2/{name}",
"connection": "AzureWebJobsDashboard",
"direction": "out"
},
{
"type": "blob",
"name": "output3",
"path": "samples-workitems/output3/{name}",
"connection": "AzureWebJobsDashboard",
"direction": "out"
},
{
"type": "blob",
"name": "output4",
"path": "samples-workitems/output4/{name}",
"connection": "AzureWebJobsDashboard",
"direction": "inout"
},
{
"type": "blob",
"name": "$return",
"path": "samples-workitems/output5/{name}",
"connection": "AzureWebJobsDashboard",
"direction": "out"
}
],
"disabled": false
}
#r "Microsoft.WindowsAzure.Storage"
open System
open System.Configuration
open System.Text
open Microsoft.WindowsAzure.Storage
open Microsoft.WindowsAzure.Storage.Blob
// Note: Can't bind Blobs to pocos (in or out) at the moment Trigger to type 'Run+Person
// https://github.com/Azure/azure-webjobs-sdk/issues/901
[<CLIMutable>]
type Person = { First:string; Last:string }
let GetBlob (storageAcc:string) containerName blobName =
let connString = ConfigurationManager.AppSettings.[storageAcc]
let storageAccount = CloudStorageAccount.Parse(connString)
let blobClient = storageAccount.CreateCloudBlobClient()
let container = blobClient.GetContainerReference(containerName)
container.GetBlockBlobReference(blobName)
let Run(inputBlob: Stream,
name: string,
log: TraceWriter,
output1: byref<string>,
output2: TextWriter,
output3: Stream,
output4: ICloudBlob) =
let message = sprintf "Got blob \n FileName: %s \n Length: %d " name inputBlob.Length
log.Verbose(message)
// output1: string
output1 <- message
// output2: TextWriter
output2.WriteLine("Hello")
output2.WriteLine("World")
// output3: Stream
let bytes = Encoding.UTF8.GetBytes("Using CloudBlockBlob directly")
output3.Write(bytes, 0, bytes.Length)
// output4: binding to ICloudBlob (could also be CloudBlockBlob)
// have to edit function.json and set direction to "inout" for it to work
output4.Metadata.["From"] <- "Mark Heath"
output4.SetMetadata();
let bytes = Encoding.UTF8.GetBytes("inout binding to ICloudBlob")
output4.UploadFromByteArrayAsync(bytes, 0, bytes.Length).Wait()
// write directly with blob storage without using an output binding
let cloudBlockBlob = GetBlob "AzureWebJobsDashboard" "samples-workitems" "outputdirect/test.txt"
let bytes2 = Encoding.UTF8.GetBytes("Using CloudBlockBlob directly")
log.Verbose("uploading text...")
cloudBlockBlob.UploadFromByteArrayAsync(bytes2, 0, bytes2.Length).Wait()
log.Verbose("text uploaded")
cloudBlockBlob.Metadata.["From"] <- "Mark Heath"
cloudBlockBlob.SetMetadata();
log.Verbose("metadata set")
// output5 is $return, so let's return a string
"Returning via $return"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.