DaveVoyles / Azure-func-blob-storage

Manipulate blob storage from an Azure Function. Simply host this project in Azure App Service.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Azure-func-blob-storage

Author(s): Dave Voyles | @DaveVoyles

Access Azure Blob Storage from an Azure Function

About

Manipulate blob storage from an Azure Function. Simply host this project in Azure App Service.

Instructions

You'll need to set the conection string to your Azure Blob Storage Account to store any content and use this function.

If testing locally...

Create a local.settings.json file, and store your connection string there, with the name ConnString. Ex:

  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=funcstoracct;AccountKey=fq8O0ie/UGgFP6lh2yA1vpXky0MT7s3BdT2tFi1cWSgZI4yPZs/Hgr6lwCaGKH/+EDEOmt7+1S4seyHJ6YRYVQ==;EndpointSuffix=core.windows.net",
    "AzureWebJobsDashboard": "",
    "ConnString": "DefaultEndpointsProtocol=https;AccountName=myaccountname;AccountKey=311666311666311666==;"
  }

That information can be found in your Azure Portal, Azure Storage Explorer, or through the Functions CLI. Here is where it appears in the portal:

Imgur

AzureBlobManager.cs uses this to connect to your blob storage account:

        private static string connString = Environment.GetEnvironmentVariable("ConnString");       
         
        public AzureBlobManager()
        {
            _storageAccount = CloudStorageAccount.Parse(connString);
            _blobClient = _storageAccount.CreateCloudBlobClient();
            _container = _blobClient.GetContainerReference(ROOT_CONTAINER_NAME);
        }

If hosting this in azure

Create your connection string in the configuration tool there. Documentation.

Passing an image to the function

This is done by making an HTTP POST request. Inside the body of the message, we want to pass in JSON content, with a key/value pair like this:

{
	"name":"http://snoopdogg.com/wp-content/themes/snoop_2014/assets/images/og-img.jpg"
}

In a tool such as Postman, I would write my message like so:

Imgur

The URL to send the message is found in the console when you start your Azure Function app. Imgur

This takes the name of the image, pre-pends the current date, and saves the image to blob storage.

About

Manipulate blob storage from an Azure Function. Simply host this project in Azure App Service.


Languages

Language:C# 100.0%