How to set content-type of media files stored on blob?

0 votes
Hello there. I have a website hosted on Azure. It is media based, and we are using JWPlayer to playback media with HTTP pseudostreaming. The media files are stored on blob in 3 formats - mp4, ogg, webm.

The issue is the content type of media files is set as application/octet-stream for all types. Due to this there are some issues in media playback and progress bar.

How can I set the appropriate Content-type of files stored on blob (like - video/mp4, video/ogg, video/webm)?

I do not want to do it manually for each file by going in blob interface. There must be some other way to do it which I am not aware of. Perhaps a config file, settings file, etc sorts. Or perhaps a code block to set up the Content-type for all files stored in a folder.

Can anyone help me out here? TIA
Jul 26, 2018 in Azure by cloudie_crank
• 1,610 points
1,318 views

1 answer to this question.

0 votes

You can use the below way:

var storageAccount = CloudStorageAccount.Parse("YOURCONNECTIONSTRING");
var blobClient = storageAccount.CreateCloudBlobClient();

var blobs = blobClient
    .GetContainerReference("thecontainer")
    .ListBlobs(useFlatBlobListing: true)
    .OfType<CloudBlockBlob>();

foreach (var blob in blobs)
{
    if (Path.GetExtension(blob.Uri.AbsoluteUri) == ".mp4")
    {
        blob.Properties.ContentType = "video/mp4";
    }
    // repeat ad nauseam
    blob.SetProperties();
}

Or set up a dictionary so you don't have to write a bunch of if statements.

answered Jul 26, 2018 by null_void
• 3,220 points

Related Questions In Azure

0 votes
1 answer

How to get the list of names of Azure blob files in a container?

We can get some additional info like Size, ...READ MORE

answered Jun 27, 2018 in Azure by club_seesharp
• 3,450 points
2,029 views
0 votes
1 answer

How to upload a file on to Azure Blob storage without writing a code?

You can find the below tools useful ...READ MORE

answered Apr 13, 2018 in Azure by club_seesharp
• 3,450 points
186 views
0 votes
1 answer

How to set default Web page for a website on Microsoft Windows Azure?

This blog post should resolve your issue: http://blogs.msdn.com/b/cesardelatorre/archive/2010/07/22/how-to-set-a-default-page-to-a-windows-azure-web-role-app-silverlight-asp-net-etc.aspx Look ...READ MORE

answered Mar 27 in Azure by Prerna
• 1,940 points
69 views
0 votes
1 answer

How can i upload to Azure Blob storage with Shared Access key?

For GetBlobReferenceFromServer to work, the blob must be present ...READ MORE

answered Jun 12, 2018 in Azure by club_seesharp
• 3,450 points
943 views
0 votes
1 answer

Azure Blob: How to open a file in browser without downloading it?

First, because I was using a byte[] the controller ...READ MORE

answered Jun 20, 2018 in Azure by club_seesharp
• 3,450 points
4,114 views
0 votes
1 answer

How to add Azure Virtual machine to an existing availability set?

You cannot associate an Availability Set to an existing ...READ MORE

answered Aug 9, 2018 in Azure by null_void
• 3,220 points
1,218 views
0 votes
1 answer

How to configure kubectl command to access remote kubernetes cluster on azure?

Found a way to access remote kubernetes ...READ MORE

answered Aug 10, 2018 in Azure by club_seesharp
• 3,450 points
3,875 views
0 votes
1 answer

How to deploy a simple static micro site on Microsoft Azure?

Try steps told in this tutorial: https://www.microsoft.com/middleeast/azureboxes/cloud-hosting-for-a-static-website.aspx This is not ...READ MORE

answered Sep 3, 2018 in Azure by null_void
• 3,220 points
54 views
0 votes
1 answer

How can we load a list of Azure blob files recursively?

Actually, there's a simpler way to do ...READ MORE

answered Aug 13, 2018 in Azure by null_void
• 3,220 points
3,143 views
0 votes
1 answer

How to determine the number of messages in an Azure Services Bus Queue?

You will get error when you try ...READ MORE

answered Jun 12, 2018 in Azure by null_void
• 3,220 points
370 views