Azure Storage Easy Web File-Hosting
Tags: azure, webdev
Published: 2020-04-06 14:35:32

---
title: Azure Storage Easy Web File-Hosting
published: true
date: 2019-01-10 16:10:00 UTC
tags: azure, webdev
canonical_url: https://sebnilsson.com/blog/azure-storage-easy-web-file-hosting/
---

In an ambition to improve my blog a little bit, I wanted to include more images in the posts but felt a **lack of a good solution for web file-hosting**. To find the best fit, I put down a check-list of features and criteria. The solution I was looking for should or must check the following:

- **Ownership of the files:** If the solution used disappears tomorrow, you can still access my files.
- **Predictable URLs:** The URL to the resources should never change. You don't want to have to update all your blog-posts or other external links floating around the internet.
- **Good tooling:** Avoiding slow web-upload, when uploading multiple and/or large files, but also easily getting an overview of your files.
- **_(Bonus)_ Pretty URLs:**"Pretty" looking URLs are easier to check for copy-paste errors, but could also potentially benefit[SEO](https://en.wikipedia.org/wiki/Search_engine_optimization).
- **_(Bonus)_ Low or no cost:** Since there are free services out there, paying for file-hosting must be worth it.

 ![Images & Tech](https://files.sebnilsson.com/web/images/azure-storage-file-hosting/lead.jpg)

## Non-fitting Alternatives

When I started evaluating alternatives, a while back, **Flickr** was still a thing. The problem was that I couldn't predictable directly link to an image I've uploaded. After feeling all the obstacles, which indicated that using Flickr for image-hosting was being actively blocked, I understood it was too much of a hack.

Historically, I've been using **Google's image hosting through Blogger** , which is where this blog started out. The problem was that this also felt like I hack and I was always worried that the URLs would change and I'd have to go through every single blog-posts I've ever made and update all images.

Services like **Dropbox** and **Google Drive** seem to actively try to block the use of their services for this, even if they are accessible through the web.

## Azure Storage for easy web file-hosting

Enter [Azure Storage](https://azure.microsoft.com/services/storage/), with its widespread adoption, familiar interface and [extremely affordably priced Blob Storage](https://azure.microsoft.com/en-us/pricing/details/storage/blobs/). It checks off all my points in the checklist and more. Giving it's backing, it's fair to assume more functionality will be added ongoingly.

[Azure Blob Storage](https://azure.microsoft.com/services/storage/blobs/) can be used to store data-blobs of almost any size in the Azure-cloud. By providing a path/key, you can read or write to that "file" at that "path". The overall [performance of Azure Storage](https://docs.microsoft.com/en-us/azure/storage/common/storage-scalability-targets) is great and also an important feature of the service, but the simple mechanisms of Azure Blob Storage make it very fast.

### Expose blob-content to the internet

So you could build a web-app which accesses your files on Azure Blob Storage and expose them through URLs in your API, but you can also **let Azure handle that for you** , by activating [anonymous read access to your blobs](https://docs.microsoft.com/azure/storage/blobs/storage-manage-access-to-resources).

You can do this on blob-level, so **you can have a dedicated blob for public files** , separately from your other blobs in the same Storage-account. These files will be read-only when you use the option `Blob (anonymous read access for blobs only)`, found under the _Access policy_-section of the selected blob.

### Upload files

Then you can use the Azure Portal, programmatically use the [Azure Blob Storage API](https://docs.microsoft.com/azure/storage/) to upload files, or you can use application [Azure Storage Explorer](https://azure.microsoft.com/features/storage-explorer/), for a friendly GUI-experience to get started.

 ![Azure Storage Explorer](https://files.sebnilsson.com/web/images/azure-storage-file-hosting/storage-explorer.png)

Now you can share your files anywhere you want, via the provided URL from Azure or through a more pretty URL, using a custom domain.

### Add a custom domain

To fulfill the criteria of pretty URLs, you can [set your own custom domain for an Azure Storage-account](https://docs.microsoft.com/en-us/azure/storage/blobs/storage-custom-domain-name). If you do not do this, the default URL for Azure Blob storage is `https://{storage-account-name}.blob.core.windows.net/{file-path}`.

### Activate Azure CDN

This is a great start for your small project to start out with, but you can in the future easily transition into using the full power of [Azure Content Delivery Network (Azure CDN)](https://azure.microsoft.com/services/cdn/) on your existing Azure Storage-account, simply by [activating it from the _Azure CDN_-section](https://docs.microsoft.com/azure/cdn/cdn-overview) in your Storage-account.