- Azure Serverless Computing Cookbook
- Praveen Kumar Sreeram
- 318字
- 2021-07-02 20:23:04
How to do it...
- Create a new Azure Function by choosing the QueueTrigger-C# from the templates.
- Provide the following details after choosing the template:
- Name your function: Please provide a meaningful name such as CreateProfilePictures.
- Queue name: Name of the Queue which should be monitored by the Azure Function. Our previous recipe created a new item for each of the valid requests coming to the HTTP trigger (named RegisterUser) into the userprofileimagesqueue Queue. For each new entry of a queue message to this Queue storage, the CreateProfilePictures trigger will be executed automatically.
- Storage account connection: Connection of the storage account where the Queues are located.
- Review all the details, and click on Create to create the new function.
- Navigate to Integrate tab then click on New Output then choose Azure Blob Storage then click on the Select button.
- In the Azure Blob Storage output section, provide the following:
- Blob parameter name: Set it to outputBlob
- Path: Set it to userprofileimagecontainer/{rand-guid}
- Storage account connection: Choose the storage account where you would like to save the Blobs:

- Once you provide all the preceding details, click on the Save button to save all the changes.
- Replace the default code of the run.csx file with the following code:
using System;
public static void Run(Stream outputBlob,string myQueueItem,
TraceWriter log)
{
byte[] imageData = null;
using (var wc = new System.Net.WebClient())
{
imageData = wc.DownloadData(myQueueItem);
}
outputBlob.WriteAsync(imageData,0,imageData.Length);
}
- Click on the Save button to save the changes.
- Let's go back to the RegisterUser function and test it by providing firstname, lastname, and ProfilePicUrl fields as we did in the Saving the profile images to Queues using Queue output bindings recipe.
- Now, navigate to the Azure Storage Explorer, and look at the Blob container userprofileimagecontainer. You will find a new Blob as shown in the following screenshot:

- You can view the image in any tool (such as MS Paint or Internet Explorer).
推薦閱讀
- Advanced Splunk
- C# 7 and .NET Core Cookbook
- Mastering phpMyAdmin 3.4 for Effective MySQL Management
- Mastering Python Scripting for System Administrators
- 從程序員到架構師:大數據量、緩存、高并發、微服務、多團隊協同等核心場景實戰
- SEO實戰密碼
- Mastering macOS Programming
- TradeStation交易應用實踐:量化方法構建贏家策略(原書第2版)
- Java程序設計:原理與范例
- Spring Boot Cookbook
- Visual Basic程序設計實踐教程
- MongoDB,Express,Angular,and Node.js Fundamentals
- C++語言程序設計
- Flink技術內幕:架構設計與實現原理
- 體驗之道:從需求到實踐的用戶體驗實戰