This is a precompiled function version of the Azure Functions sample CoderCards.
-
This sample uses the new precompiled function feature. The project also uses WebJobs attributes instead of
function.json
. Use theFunctionName
attribute to provide the name that will appear in the portal. -
There are two versions of the project:
- CoderCards.csproj, which requires Visual Studio 2017 Update 3 and the Azure Functions Tools VSIX. When the project is built, the file
function.json
is generated in the build output folder. - CoderCardsWebProj.csproj, which is a regular web project. To convert attributes to
function.json
, it runs Runner.exe as a post-build step. To make the project runnable with F5, you must modify the project start action to launch the Azure Functions Core Tools. (See intructions below.)
- CoderCards.csproj, which requires Visual Studio 2017 Update 3 and the Azure Functions Tools VSIX. When the project is built, the file
-
There are two functions defined in this project:
- RequestImageProcessing. HTTP trigger that writes a queue message. The request payload must be in the following form:
{ "PersonName": "Scott Guthrie", "Title": "Red Polo Connoisseur", "BlobName": "Scott Guthrie-Red Polo Connoisseur.jpg" }
-
GenerateCard. Queue trigger that binds to the blob specified in the BlobName property of the queue payload. Based on the predominant emotion of the input image, it generates a card using one of 4 card templates.
- The card is written to the output blob container specified by the app setting
output-container
.
- The card is written to the output blob container specified by the app setting
Key | Description |
---|---|
AzureWebJobsStorage | Storage account connection string |
EmotionAPIKey | Key for Cognitive Services Emotion API |
input-queue | Name of Storage queue for to trigger card generation. Use a value like "local-queue" locally and "input-queue" on Azure |
input-container | Name of Storage container for input images. Use a value like "local-card-input" locally and "card-input" on Azure |
output-container | Name of Storage container for output images. Use a value like "local-card-output" locally and "card-output" on Azure |
HOME | Set to "." when running locally. Is automatically set on Azure |
SITE_PATH | Use "." when running locally. Use site\\wwwroot on Azure |
-
If you're using Visual Studio 2017 Update 3 and the Azure Functions Tools VSIX, open the project CoderCards.csproj. F5 will automatically launch the Azure Functions Core tools.
-
If you're using CoderCardsWebProj.csproj, you must customize the project start action to launch the Azure Functions Core tools. See screenshot below.
- Install the Azure Functions Core Tools from npm.
- Right-click CoderCardsWebProj and open Properties.
- In the Web tab, choose Start External Program
- For the program path, enter the path to
func.exe
for the Azure Functions CLI. The path will be similar to likeC:\Users\USERNAME\AppData\Roaming\npm\node_modules\azure-functions-cli\bin\func.exe
- For Command line arguments set
host start --cors *
- For Working directory, specify the root of the project
CoderCardsWebProj
on your machine.
TBD
-
Choose images that are square and upload to the
card-input
container. -
Send an HTTP request using Postman or CURL, specifying the path of the blob you just uploaded:
{ "PersonName": "My Name", "Title": "My Title", "BlobName": "BlobFilename.jpg" }
-
The demo uses System.Drawing, which is NOT recommended for production apps. To learn more, see Why you should not use System.Drawing from ASP.NET applications.
-
Happy faces get a multiplier of 4, angry gets a multiplier of 2. I encourage you to tweak for maximum comedic effect!
-
Creating an HTTP trigger that writes a queue message is just one line of code!
-
Using a queue message to trigger blob processing is preferable to a blob trigger, as it is easier to ensure transactional processing. Also, blob triggers can be delayed for up to 10 minutes on the Consumption plan.
-
By binding to a POCO, you can use the payload of a trigger to configure an input binding. In this example, we binding to the
BlobName
property in the queue message. -
The input binding is just a byte array, which makes it easy to manipulate with memory streams (no need to create new ones). Other binding types for C# are Stream, CloudBlockBlob, etc, which is very flexible. The output binding is just a stream that you just write to.