Email: Password:       Forgot Password 
    .netCodeSG
A Saarsha Group Online Community for dot net codes group like C#, Asp.NET, VB.NET, Sharepoint, JavaScript, JQuery, Ajax, SQL, WCF, WPF.
 
TECHNOLOGIES:
 

Azure Create Function App from Portal - Blob Trigger to resize Image

Article:
Viewed:  122 
Posted On:  24/09/2019 18:05:50 
How we can create a function app from Azure Portal? Add Blob Trigger in Azure Function.  

 

In this article, I am going to show, 

  • what is Azure Function?
  • How we can create an Azure Function from Azure Portal?
  • How we can trigger our Azure Function?

I am going to explain all above through an example. I have created a Storage Account with two container

  1. source
  2. destination

What I am going to create in this article:

Azure Portal – Function App – BlobTriggerFunction.  I will upload an Image to source Container and will process on it and after resizing it, I will save this pic to destination Container.

Open Azure Portal: https://portal.azure.com

Login with you subscription.

Below is my Azure Storage Account:

1.png

Image 1.

Now add a new Azure Function:

2.png

Image 2.

Function App has been created. Now add + to add new function.

3.png

Image 3.

Make sure Run time version is ~1 of newly created function App.

4.png

Image 4.

Now add a trigger for this function. So here, I am going to use Blob Trigger.

5.png

Image 5.

Here we are going to upload Images in source container and will process on it and will save resized image in destination container.

6.png

Image 6.

Below is default code.

7.png

Image 7.

Now add a project.json file

8.png

Image 8.

Add below code in your project.json file. Save it. It will install NuGet packages. See log.

{
"frameworks":{
             "net46":{
                "dependencies":{
                            "ImageResizer":"4.0.5"
                               
                    }
             }
}

 

 

9.png

Image 9.

Now click on Integrate on Left side.

10.png

Image 10.

Set output.

11.png

Image 11.

Open run.csx file and add below code:

#r "System.Drawing" 

using ImageResizer;
using System.Drawing;
using System.Drawing.Imaging; 

public static void Run(Stream inImage, string name, string extension, Stream outImage, TraceWriter log)
{
    log.Info($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {inImage.Length} Bytes"); 

    var settings= new ImageResizer.ResizeSettings
                       {
                                MaxWidth=250,
                                Format="jpg",
                                Quality=50
                     };
     ImageResizer.ImageBuilder.Current.Build(inImage,outImage,settings);   
} 

 

12.png

Image 12.

Now upload an image in source container from Azure portal or Storage Explorer:

13.png

Image 13.

Image uploaded in source Container:

14.png

Image 14.

Blob will trigger and will save Image in destination Container after resizing it:

15.png

Image 15.

Check your Image J

16.png

Image 16.

  Comment:
         HOME   |   Submit Article   |   Contact Us   |   About Us   |   Terms & Condition   |   Advertise With us