August 2013 - Digital Tool Factory blog August 2013 - Digital Tool Factory blog

The Digital Tool Factory Blog

How to set mime types, aka Content Types with Windows Azure Storage

The Problem

I recently came across the conundrum of files not being availble for download after I uploaded them to Windows Azure Storage.

The Cause

Usually the problem is an incorrect mime type, but since Azure does not have mime types I had to do some more digging.

The Solution

It turns out there is a property called “ContentType” that must be set on the Azure Storage Blob programatically – here is an example

CloudBlockBlob blockBlob = container.GetBlockBlobReference(filename);

if (GetFileExtension(filename).ToUpper() == “.SWF”)
blockBlob.Properties.ContentType = “application/x-shockwave-flash”;
else if (GetFileExtension(filename).ToUpper() == “.MP4”)
blockBlob.Properties.ContentType = “video/mp4”;

Once I did that everything worked as intended.

Aug 13

Written By Steve French


Copyright 2011 Digital Tool Factory. All Rights Reserved. Powered by raw technical talent. And in this case, WordPress.