This post originally appeared on the FeedbackHound Blog. Feedbackhound is now focused on android development, so we have moved all .NET posts back to DevTrends.
Setting the content disposition header
Setting the content disposition header using the Azure Blob Storage Client Library is very simple. You only need to add one line to your existing upload code:
blob.Properties.ContentDisposition = "attachment; filename=" + downloadName;
Depending on the age of your storage account, this may be all that is required but if you find that the header is not having any effect, read on. If your file is uploading without error but when you come to download the file, it looks as though the content-disposition header is being ignored, then there is a good chance that you have an empty or out of date DefaultServiceVersion.
Setting the DefaultServiceVersion
What the heck is a DefaultServiceVersion you ask. Well you can read more about versioning on MSDN but suffice to say that it is required if you want to get ContentDisposition working.
Setting the DefaultServiceVersion is relatively simple. Just execute the following code:
var blobClient = storageAccount.CreateCloudBlobClient(); var serviceProperties = blobClient.GetServiceProperties(); serviceProperties.DefaultServiceVersion = "2013-08-15"; blobClient.SetServiceProperties(serviceProperties);
As with enabling CORS support, you only need to do this once as far as I can tell.
This info came from a stackoverflow answer by Gaurav Mantri so a big thank you to him as there is very little information out there at present.
Useful or Interesting?
If you liked the article, we would really appreciate it if you would share it with your Twitter followers.Share on Twitter »
Comments are now closed for this article.