This example demonstrates a basic function which watches a blob storage container for a new image, when triggered will use the Jimp node module to create a thumbnail of that image and place it in another blob folder.
-
Clone (or download) this repo
-
In the Azure portal create a new Resource Group
-
Within the Resource Group create a new Storage Account of type 'General'.
Note: Your storage account name must be unique
- Open the newly created storage account, select 'Blobs' and create two containers named 'uploads' and 'thumbs'
- Create a new 'Function App' in the Resource Group
-
Open the Function App
-
Click the + next to Functions to add a new Function
-
Choose 'create your own custom function' and select Javascript for language and then choose 'BlobTrigger - Javascript' for the function template.
-
In the 'Azure Blob Storage Trigger' section click on 'new' to connect to your storage account, and then choose your storage account from the list.
-
Change the path to point to uploads/{name}
-
Paste the contents of index.js from the git repo into your index.js, overwriting the current contents, and then click 'Save'.
-
Click on 'View Files' in the right hand pane and then select the 'function.json' file.
-
Add the second section for the output (outbound) of the function, you can copy from the git repo. Make sure you update the 'connection' name to match the connection name used in the input were your 'uploads' and 'thumbs' containers are located. Also add the "dataType": "binary" line to the inbound section. When complete your function.json should look something like the following:
-
Save the function.
-
In the 'View Files' window create a new file called 'package.json' and copy and paste the package.json contents from the git repo. Update the name in the file to match your function name and then save.
-
Click on the top level of the function app and then go to 'Platform Features'.
-
Under 'Development Tools' open 'Advanced tools (Kudu)'. This will open up the Kudu environment editor.
-
Go to 'Debug Console' --> 'CMD'
-
Navigate to 'site/wwwroot/YourFunctionName'
-
Run the following to install the node modules
npm install
- Navigate back to your function so that you can see the log output. In a separate window open the 'uploads' blob container and upload a file. Back in the function app watch the logs to see the process execute. You can then look in the thumbs container for the thumbnail.