Home:ALL Converter>How to upload Stream to Azure Media Services

How to upload Stream to Azure Media Services

Ask Time:2013-02-21T02:34:52         Author:Albert Bori

Json Formatter

We're using ASP.NET MVC 4 to allow users to upload video and audio through our website. I would like to use Azure Media Service as the back-end for this.

While following Azure's tutorial, the issue I've run into is that the Azure Media Services SDK doesn't appear to allow uploading a raw stream of data. Instead, the only upload method I could find uses a path string argument.

I would like to avoid saving the file to disk (it's already streamed to disk by default), and be able to stream the request posted file right through to Azure.

Here is my code thus far:

public void SaveMedia(string fileName, System.IO.Stream stream)
{
    CloudMediaContext mediaCloud = new CloudMediaContext("account", "key");
    AssetCreationOptions assetOptions = new AssetCreationOptions();
    var asset = mediaCloud.Assets.Create(fileName, assetOptions);

    var assetFile = asset.AssetFiles.Create(fileName);

    var accessPolicy = mediaCloud.AccessPolicies.Create(fileName, TimeSpan.FromDays(3), AccessPermissions.Write | AccessPermissions.List);

    var locator = mediaCloud.Locators.CreateLocator(LocatorType.Sas, asset, accessPolicy);

    assetFile.Upload("????????????");

    locator.Delete();
    accessPolicy.Delete();
}

How does one accomplish this? Would this conflict with any "best practices" for handling uploads using ASP.NET MVC 4 and Azure Media Services?

Author:Albert Bori,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/14987405/how-to-upload-stream-to-azure-media-services
yy