Converting Image Hotlinks to Azure Storage Images

While working on a current project, I found myself with a need to cache media that I was collecting from various websites to my Azure Storage account. Then utilize the storage as somewhat of a Content Delivery Network (CDN) for my images and media.

I found a good article online about how to configure the storage account as a CDN. Which told me very quickly how to set it all up and configure it for my purposes. So the only challenge was to implement the logic to pull the images in there.

The following function pretty much does it all. First there is a field that is included in my model called “MediaUri”. This field is populated on the view with a URL for an image out on the web, say from Wikipedia for example. However this function, will convert that hotlink URL into a cdn.monkeyboxtech.com URL after downloading and caching the image to the CDN storage area.

Note this example relies on the Azure SDK tools being installed.

Then, in my web.config file for this application I have an app settings key that helps connect the cloud storage account. Of course you’d replace the <omit> with the actual values.

That is pretty much all there is to it. By using the Azure SDK tools for .NET, caching an image for later hosting from your storage account couldn’t be much easier.

Leave a Reply

Your email address will not be published. Required fields are marked *