Skip to content

Commit

Permalink
Merge pull request #17 from mhopkins-msft/master
Browse files Browse the repository at this point in the history
Updated to Azure Storage v12 libraries
  • Loading branch information
ggailey777 authored Mar 13, 2020
2 parents 3ff9c6d + 7cc1ceb commit c2a5d34
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
4 changes: 2 additions & 2 deletions ImageFunctions.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28010.2036
# Visual Studio Version 16
VisualStudioVersion = 16.0.29709.97
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ImageFunctions", "ImageFunctions\ImageFunctions.csproj", "{B6440771-70B9-4353-92B5-216B49EE9E72}"
EndProject
Expand Down
10 changes: 6 additions & 4 deletions ImageFunctions/ImageFunctions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
<AzureFunctionsVersion>v2</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.EventGrid" Version="2.0.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventGrid" Version="2.0.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="1.0.22" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.2.0" />
<PackageReference Include="Microsoft.Azure.EventGrid" Version="3.2.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventGrid" Version="2.1.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="3.0.10" />
<PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="1.1.3" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.2" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-beta0005" />
</ItemGroup>
<ItemGroup>
Expand Down
17 changes: 7 additions & 10 deletions ImageFunctions/Thumbnail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
// Use for local testing:
// https://{ID}.ngrok.io/runtime/webhooks/EventGrid?functionName=Thumbnail

using Azure.Storage.Blobs;
using Microsoft.Azure.EventGrid.Models;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.EventGrid;
using Microsoft.Extensions.Logging;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using Newtonsoft.Json.Linq;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats;
Expand All @@ -28,15 +27,15 @@

namespace ImageFunctions
{
public static class Thunbnail
public static class Thumbnail
{
private static readonly string BLOB_STORAGE_CONNECTION_STRING = Environment.GetEnvironmentVariable("AzureWebJobsStorage");

private static string GetBlobNameFromUrl(string bloblUrl)
{
var uri = new Uri(bloblUrl);
var cloudBlob = new CloudBlob(uri);
return cloudBlob.Name;
var blobClient = new BlobClient(uri);
return blobClient.Name;
}

private static IImageEncoder GetEncoder(string extension)
Expand Down Expand Up @@ -89,11 +88,9 @@ public static async Task Run(
{
var thumbnailWidth = Convert.ToInt32(Environment.GetEnvironmentVariable("THUMBNAIL_WIDTH"));
var thumbContainerName = Environment.GetEnvironmentVariable("THUMBNAIL_CONTAINER_NAME");
var storageAccount = CloudStorageAccount.Parse(BLOB_STORAGE_CONNECTION_STRING);
var blobClient = storageAccount.CreateCloudBlobClient();
var container = blobClient.GetContainerReference(thumbContainerName);
var blobServiceClient = new BlobServiceClient(BLOB_STORAGE_CONNECTION_STRING);
var blobContainerClient = blobServiceClient.GetBlobContainerClient(thumbContainerName);
var blobName = GetBlobNameFromUrl(createdEvent.Url);
var blockBlob = container.GetBlockBlobReference(blobName);

using (var output = new MemoryStream())
using (Image<Rgba32> image = Image.Load(input))
Expand All @@ -104,7 +101,7 @@ public static async Task Run(
image.Mutate(x => x.Resize(thumbnailWidth, height));
image.Save(output, encoder);
output.Position = 0;
await blockBlob.UploadFromStreamAsync(output);
await blobContainerClient.UploadBlobAsync(blobName, output);
}
}
else
Expand Down

0 comments on commit c2a5d34

Please sign in to comment.