Based on https://ppolyzos.com/2016/12/30/resize-images-using-azure-functions/ I have the following C# code to resize an image using Azure Functions.
#r "Microsoft.WindowsAzure.Storage"
using ImageResizer;
using ImageResizer.ExtensionMethods;
using Microsoft.WindowsAzure.Storage.Blob;
public static void Run(Stream inputBlob, string blobname, string blobextension, CloudBlockBlob outputBlob, TraceWriter log)
{
log.Info($"Resize function triggered\n Image name:{blobname} \n Size: {inputBlob.Length} Bytes");
log.Info("Processing 520x245");
/// Defining parameters for the Resizer plugin
var instructions = new Instructions
{
Width = 520,
Height = 245,
Mode = FitMode.Carve,
Scale = ScaleMode.Both
};
/// Resizing IMG
Stream stream = new MemoryStream();
ImageBuilder.Current.Build(new ImageJob(inputBlob, stream, instructions));
stream.Seek(0, SeekOrigin.Begin);
/// Changing the ContentType (MIME) for the resulting images
string contentType = $"image/{blobextension}";
outputBlob.Properties.ContentType = contentType;
outputBlob.UploadFromStream(stream);
}
The result will be an image named 520x245-{blobname}.{blobextension}
.
I would like the code to run only if the resulting image does not already exist in the blob container.
How can I get the existing files on the container?