How to upload Stream to Azure Media Services How to upload Stream to Azure Media Services azure azure

How to upload Stream to Azure Media Services


You should use not use the Azure Media Services to do the upload, it is not designed for inbound-stream-to-azure-storage-blob, which is what you are describing.

Use the Azure Storage SDK directly (use v1.7 to avoid rebinding issues).The Storage SDK allows stream writes to blob.To do this, you need to first get a SAS write locator (looks like you're there), then use the locator.Path.Segments to find the asset container. Then use this to upload directly using CloubBlobClient in the Storage SDK -- it offers a stream write function somewhere.

Note in your code above: you are not specifying AssetCreationOptions.None, therefor it will assume that the files in storage will be storage-encrypted (default transfer mechanism is secure, not unsecured). I don't think you are going to do the storage encryption on your file-stream prior to upload, so you'd best set that to AssetCreationOptions.None.

Personally, I would not go this route. Read my blog post on 'create your own youtube':http://blog-ndrouin.azurewebsites.net/?p=1471

In it, there is a full example of client-uploaded content using a SAS url provided by the server side (which has your account credentials, that you probably don't want floating around on your client-side!).

The client, however, must be able to do a PUT into storage using that SAS URL. In my case, I used a C# command line app. You will not be able to do this in HTML5 unless your web-page is hosted on the same domain as the target storage account. If your web-page (or an I-Frame that manages the uploads) is not in the same domain as your storage account, this will trigger a CORS "OPTIONS" call in HTML5 to the Azure Storage REST layer, which not yet support CORS.

Alternatives to an HTML5 I-Frame hosted in your storage account are: Sliverlight or Flash upload shims with a cross-domain file in the $root of your storage account (or perhaps those plugin objects hosted in your storage account to avoid the cross-domain-file request).

I would discourage uploading the filestream to the server in a POST. This makes your web-service a bottleneck for all inbound files; and a long POST is not particularly stable: your app-pool can get recycled in the middle of an upload and you're toast.

PS. Our team (Windows Azure Media Services) primarily monitors this forum:

http://social.msdn.microsoft.com/Forums/en-US/MediaServices/threads