Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Streaming video from Azure blob storage

I'm having problems getting an .mp4 video stored in Azure blob storage to show in a website hosted on Azure. The video type is set to video/mp4, the storage account is not public, but it is linked to the web role, and I've updated the version using this bit of code:

var credentials = new StorageCredentials("myaccountname", "mysecretkey"); 
var account = new CloudStorageAccount(credentials, true); 
var client = account.CreateCloudBlobClient(); 
var properties = client.GetServiceProperties(); 
properties.DefaultServiceVersion = "2012-02-12"; 
client.SetServiceProperties(properties); 

I'm not using any video player, just the HTML5 video tag. I also don't need anything fancy, I just want the video to play.

Looking at the network tab in Chrome's dev tools, there are two entries for the GET request to fetch the video. The first one has a status of (pending) and the next one is (canceled).

I also gave it a link to a video which is in the website's content folder. This one also starts as pending but is resolved with a 204 Partial Content and the video plays just fine.

I'm out of stuff to look at, and any help and pointers are appreciated.

like image 208
Ivan Pintar Avatar asked Feb 14 '23 20:02

Ivan Pintar


1 Answers

Based on your comments above, what you need is a Shared Access Signature. Use the code below to create a shared access signature on your mp4 file.

        var credentials = new StorageCredentials("myaccountname", "mysecretkey");
        var account = new CloudStorageAccount(credentials, true);
        var container = account.CreateCloudBlobClient().GetContainerReference("yourcontainername");
        var blob = container.GetBlockBlobReference("yourmp4filename");
        var sas = blob.GetSharedAccessSignature(new SharedAccessBlobPolicy()
        {
            Permissions = SharedAccessBlobPermissions.Read,
            SharedAccessExpiryTime = DateTime.UtcNow.AddHours(1),//Set this date/time according to your requirements
        });
        var urlToBePlayed = string.Format("{0}{1}", blob.Uri, sas);//This is the URI which should be embedded in your video player.
like image 172
Gaurav Mantri Avatar answered Feb 17 '23 09:02

Gaurav Mantri