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
6,216 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
21,027 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
1,292 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, 2019 in Azure by Prerna
• 1,960 points
2,652 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
3,377 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
23,411 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 10, 2018 in Azure by null_void
• 3,220 points
7,604 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 11, 2018 in Azure by club_seesharp
• 3,450 points
9,688 views
0 votes
2 answers

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

Create an Azure Storage account ("hot file" ...READ MORE

answered Jun 4, 2020 in Azure by René
1,150 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 14, 2018 in Azure by null_void
• 3,220 points
18,719 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
4,190 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP