I am posting pictures to Azure blob storage. As I am storing full resolution images, I want to maintain a separate collection(s) of thumbnails(or previews) of the images. Is it possible to write a script(or a hook) where when an image is uploaded to the blob storage, the thumbnail of the image is also automatically saved.
Please inform if there's a way to script this.
I don't want to do the resizing on the client side or on the server side. I am using SAS to enable the client to upload the images to blob storage directly. I can send the image to the Mobile Service(server) I am running where the image can be resized and uploaded to the blob storage. But I don't want to overload the server with these calls.
Yes that is indeed possible, you can do this by deploying a WebJob using a BlobTrigger that takes the inputstream for the newly created blob and let you modify it to an output blob, the code would look like this using the excellent imageresizing.net library:
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 have seen problems when we reach a lot of pictures with the webjob throwing OutOfMemoryExceptions when it do the initial check for unprocessed blobs, but that might be specific to our setup (We have a lot of pictures). We changed to manually adding a message to a storage queue and instead have a webjob process it using a QueueTrigger.
Continue to upload to Storage, then send an event to EventHub. You can implement an EventProcessor and host that code in a worker role. The EventProcessor can get the uploaded image from storage, do resizing, and save resized images back to storage. The advantage of this model is it's scalable, you can scale up or down as your traffic changes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With