-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Azure Serverless Computing Cookbook
By :

The previous recipe highlighted how to receive two string parameters, firstname
and lastname
, in the Request body and store them in Azure Table storage. In this recipe, let's add a new parameter named ProfilePicUrl
for the profile picture of the user that is publicly accessible via the internet. In this recipe (and the next), you'll learn about the process of extracting the URL of an image and saving it in the blob container of an Azure storage account.
While the ProfilePicUrl
input parameter can be used to download the picture from the internet, in the previous recipe, Persisting employee details using Azure Table storage output bindings, this was not feasible due to the time required to process the large size of the image, which might hinder the performance of the overall application. For this reason, it is faster to grab the URL of the profile picture and store it in a queue, which can be processed later before storing it in the blob.
We'll be updating the code of the RegisterUser
function that was used in the previous recipes.
Perform the following steps:
RegisterUser
HTTP trigger function.Message parameter name: Set the name of the parameter to objUserProfileQueueItem
, which will be used in the Run
method.
Queue name: Set the queue name to userprofileimagesqueue
.
Storage account connection: It is important to select the right storage account in the Storage account connection field.
RegisterUser
in this example) or the run.csx
file and make the changes shown in the following code:public static async Task<IActionResult> Run( HttpRequest req, CloudTable objUserProfileTable, IAsyncCollector<string> public static async Task<IActionResult> Run( HttpRequest req, CloudTable objUserProfileTable, IAsyncCollector<string> objUserProfileQueueItem, ILogger log) {.... string firstname= inputJson.firstname; string profilePicUrl = inputJson.ProfilePicUrl; await objUserProfileQueueItem.AddAsync(profilePicUrl); .... objUserProfileTable.Execute(objTblOperationInsert); }
IAsyncCollecter
parameter to the Run
method and just passing the required message to the AddAsync
method. The output bindings will take care of saving ProfilePicUrl
to the queue. Now, click on Save to save the code changes in the code editor of the run.csx
file.ProfilePicUrl
, to the Request body and then clicking on the Run button in the Test tab of the Azure Functions code editor window. Replace "URL here"
with the URL of an image that's accessible over the internet; you'll need to make sure that the image URL provided is valid:{ "firstname": "Bill", "lastname": "Gates", "ProfilePicUrl":"URL here" }
userprofileimagesqueue
, which is the queue name that was provided in step 3.In this recipe, we added a queue message output binding and made the following changes to our existing code:
out string objUserProfileQueueItem
, which binds the URL of the profile picture as queue message content.AddAsync
method of IAsyncCollector
in the Run
method that saves the profile URL to the queue as a queue message.In this recipe, you learned how to receive a URL of an image and save it in the blob container of an Azure storage account. In the next recipe, we'll store an image in Azure Blob Storage.