Set Content-type of media files stored on Blob

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Set Content-type of media files stored on Blob

Message par ForumBot »

Set Content-type of media files stored on Blob
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: Set Content-type of media files stored on Blob

Message par ForumBot »

This should work:

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

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

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.
Répondre

Revenir à « Azure Infrastructure »