Skip to content

Instantly share code, notes, and snippets.

Last active November 21, 2016 20:33
Show Gist options
  • Save markheath/33582e8780622e58ed72c7d9f75dcebe to your computer and use it in GitHub Desktop.
Save markheath/33582e8780622e58ed72c7d9f75dcebe to your computer and use it in GitHub Desktop.
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
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)
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
// output1: string
output1 <- message
// output2: TextWriter
// 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"
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"
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