Automatically generate thumbnails or preview images when sent to Azure blob storage

I post photos to the Azure blob repository. Since I store full-resolution images, I want to keep a separate collection of thumbnails (or previews) of the images. Is it possible to write a script (or a hook) where, when the image is uploaded to the blob repository, the image thumbnail is also automatically saved.

Please advise if there is a script method.

I do not want to make resizing on the client side or on the server side. I use SAS so that the client can upload images to the blob store directly. I can send the image to the mobile service (server) on which I run, where the image can be changed and uploaded to the blob repository. But I do not want to overload the server with these calls.

+7
azure azure-storage azure-storage-blobs
source share
2 answers

Yes, it’s really possible, you can do this by deploying WebJob using BlobTrigger, which takes the input stream for the newly created blob and allows you to modify it to the output block, the code will look like this using the excellent .NET library image:

public static void ResizeMicroImages( [BlobTrigger("orig/{name}.{ext}")] Stream input, [Blob("90x126/{name}.png", FileAccess.Write)] Stream output ){ ImageBuilder.Current.Build(new ImageJob(input, output, new Instructions() { AutoRotate = true, Width = 90, Height = 126, OutputFormat = OutputFormat.Png, })); } 

However, in our setup, we encountered problems when we reach a large number of photos with the help of a web husband throwing OutOfMemoryExceptions, when he performs an initial check of raw drops, but this may be specific to our installation (we have many photos). We manually changed the addition of the message to the storage queue and instead performed the webjob procedure using QueueTrigger.

+5
source share

Keep uploading to the repository and then dispatch an EventHub event. You can implement EventProcessor and place this code in a working role. EventProcessor can load the downloaded image from the repository, resize and save the resized images back to the repository. The advantage of this model is its scaling, you can scale up or down as traffic changes.

+4
source share

All Articles