Saving the profile images to Queues using Queue output bindings
In the previous recipe, you have learnt how to receive two string parameters firstname
and lastname
in the Request body,
and store them in the Azure Table storage. In this recipe, you will learn how to receive a URL of an image and save the same in the Blob container of an Azure Storage account.
We could have processed the downloaded user profile image in the recipe Persisting employee details using Azure Storage table output bindings. However, keeping in mind the size of the profile pictures, the processing of images on the fly in the HTTP requests might hinder the performance of the function. For that reason, we will just grab the URL of the profile picture and store it in Queue, and later we can process the image and store it in the Blob.
Getting ready
We will be updating the code of the RegisterUser
function that we have used in the previous recipes.
How to do it…
- Navigate to the
Integrate
tab of theRegisterUser
HTTP trigger function. - Click on the
New Output
button and selectAzure Queue Storage
then click on theSelect
button. - Provide the following parameters in the
Azure Queue Storage
output
settings:Queue name
: Set the value of the Queue name asuserprofileimagesqueue
Storage account connection
: Please make sure that you select the right storage account in theStorage account connection
fieldMessage parameter name
: Set the name of the parameter toobjUserProfileQueueItem
which will be used in theRun
method
- Click on
Save
to the create the new output binding.
- In this recipe, we will look at another approach of grabbing the request parameters for which we will use the Newtonsoft.JSON library to parse the JSON data. Let's navigate to the
View files
tab as shown in the following screenshot:

- As shown in the preceding screenshot, click on
Add
to add a new file. Please make sure that you name it asproject.json
as shown in the preceding screenshot. - Once the file is created, add the following code to the
project.json
file. The following code adds the reference of theNewtonsoft.Json
library.
{ "frameworks" : { "net46": { "dependencies":{ "Newtonsoft.Json" : "10.0.2" } } } }
- Navigate back to the code editor by clicking on the function name (
RegisterUser
in this example) and paste the following code:
#r "Microsoft.WindowsAzure.Storage" using System.Net; using Microsoft.WindowsAzure.Storage.Table; using Newtonsoft.Json; public static void Run(HttpRequestMessage req, TraceWriter log, CloudTable objUserProfileTable, out string objUserProfileQueueItem ) { var inputs = req.Content.ReadAsStringAsync().Result; dynamic inputJson = JsonConvert.DeserializeObject<dynamic> (inputs); string firstname= inputJson.firstname; string lastname=inputJson.lastname; string profilePicUrl = inputJson.ProfilePicUrl; objUserProfileQueueItem = profilePicUrl; UserProfile objUserProfile = new UserProfile(firstname, lastname, profilePicUrl); TableOperation objTblOperationInsert = TableOperation.Insert(objUserProfile); objUserProfileTable.Execute(objTblOperationInsert); } public class UserProfile : TableEntity { public UserProfile(string lastname, string firstname, string profilePicUrl) { this.PartitionKey = "p1"; this.RowKey = Guid.NewGuid().ToString(); this.FirstName = firstname; this.LastName = lastname; this.ProfilePicUrl = profilePicUrl; } public UserProfile() { } public string FirstName { get; set; } public string LastName { get; set; } public string ProfilePicUrl {get; set;} }
- Click on
Save
to save the code changes in the code editor of therun.csx
file.
- Let's test the code by adding another parameter
ProfilePicUrl
to theRequest body
shown as follows then click on theRun
button in theTest
tab of the Azure Function code editor window: The image used in the below JSON might not exist when you are reading this book. So, Please make sure that you provide a valid URL of the image.
{ "firstname": "Bill", "lastname": "Gates", "ProfilePicUrl":"https://upload.wikimedia.org/wikipedia/ commons/1/19/Bill_Gates_June_2015.jpg" }
- If everything goes fine you will see the
Status : 200 OK
message, then the image URL that you have passed as an input parameter in theRequest body
will be created as a Queue message in the Azure Storage Queue service. Let's navigate to Azure Storage Explorer, and view the Queue nameduserprofileimagesqueue
, which is the Queue name that we have provided in the Step 3. Following is the screenshot of the Queue message that was created:

How it works…
In this recipe, we have added Queue message output binding and made the following changes to the code:
- Added a reference to the
Newtonsoft.Json
NuGet library in theproject.json
file - Added a new parameter named
out string objUserProfileQueueItem
which is used to bind the URL of the profile picture as a Queue message content - We have also made the
Run
method synchronous by removing async as it doesn't allow us to haveout
parameters
There's more…
The project.json
file contains all the references of the external libraries that we may use in the Azure Function.
Note
At the time of writing, Azure Function Runtime only supports .NET Framework 4.6.
See also
- The Persisting employee details using Azure Storage table Output Bindings recipe