How to set mime types, aka Content Types with Windows Azure Storage - Digital Tool Factory blog How to set mime types, aka Content Types with Windows Azure Storage - 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”;
}
blockBlob.SetProperties();

Once I did that everything worked as intended.

 

Written By Steve French

 

Leave a Reply

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






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