如何上传流天青媒体服务 [英] How to upload Stream to Azure Media Services

查看:212
本文介绍了如何上传流天青媒体服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用ASP.NET MVC 4允许用户通过我们的网站上传的视频和音频。我想用的Azure媒体服务作为后端这一点。

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.

在以下<一个href=\"http://www.windowsazure.com/en-us/develop/Media-Services/how-to-guides/media-services-dotnet/\">Azure's教程,我碰到的问题是,在Azure媒体服务SDK不会出现让上传数据的原始流。相反,只有上传的方法我能找到使用路径字符串参数。

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.

我想避免将文件保存到磁盘(它已经被传输到磁盘默认),并能够流请求的权利,通过Azure的发布文件。

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.

下面是我的code迄今:

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();
}

怎样才能做到这一点?将与使用ASP.NET MVC 4的Azure媒体服务的最佳实践为处理上传这个矛盾呢?

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

推荐答案

您应该使用不使用的Azure媒体服务做上传,它不适合入站流到Azure的存储斑点,这是你所描述的。

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.

使用了Azure存储SDK直接(使用V1.7,以避免重新绑定的问题)。
存储SDK允许流写入到BLOB。
要做到这一点,你需要先得到一个SAS写入定位器(貌似你在那里),然后使用locator.Path.Segments找到资产的容器。然后使用这个直接在存储SDK使用CloubBlobClient上传 - 它的地方,提供了一种流写入功能

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.

请注意在code以上:你没有指定AssetCreationOptions.None,为此它会假设存储中的文件将存储加密(默认传输机制是安全的,没有不安全的)。我不认为你会做之前你的文件流上传的存储加密,所以你最好设置为AssetCreationOptions.None。

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.

就个人而言,我不会走这条路。阅读创建您自己的YouTube我的博客文章:
<一href=\"http://blog-ndrouin.azurewebsites.net/?p=1471\">http://blog-ndrouin.azurewebsites.net/?p=1471

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

在这,还有的使用由服务器端提供的SAS客户端的URL上传的内容的一个完整的示例(其中有您的帐户凭据,你可能不希望漂浮在您的客户端!)。

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!).

客户端,但是,必须是能够做到使用SAS URL的入库。就我而言,我用C#命令行应用程序。除非你的网页是在同一个域中的对象存储帐户托管,你将不能够做到这一点的HTML5。如果你的网页(或管理上传I帧)不在同一个域中您的存储账户,这将触发在HTML5中的Azure存储REST层,它还不支持CORS一个CORS选项呼吁

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.

替代在您的存储账户托管的HTML5 I帧是:Sliverlight的或Flash与您的存储账户的$根跨域文件上传垫片(或者在您的存储账户托管这些插件对象,以避免跨域文件要求)。

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).

我会劝阻上传FILESTREAM在一个POST的服务器。这使你的网络服务,为所有入站文件的瓶颈;和长POST是不是特别稳定。您的应用程序池可以得到回收在上传的中间,你就完了。

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。我们的团队(Windows Azure的媒体服务),主要是监视该论坛:

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

<一个href=\"http://social.msdn.microsoft.com/Forums/en-US/MediaServices/threads\">http://social.msdn.microsoft.com/Forums/en-US/MediaServices/threads

这篇关于如何上传流天青媒体服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆