YouTube的API集成ASP.NET - 上传视频单页 [英] YouTube API integration ASP.NET - upload video with a single page

查看:150
本文介绍了YouTube的API集成ASP.NET - 上传视频单页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试使用谷歌的YouTube的API,直接通过浏览器上传从我们的网站,YouTube视频。

we are trying to use the Google YouTube API to upload videos from our website to YouTube through the browser directly.

该API的工作分两个步骤,第一步我们需要与所有喜欢的标题,标签,说明,类别等元数据创建一个视频对象,这时我们就需要与此对象发送一个请求到YouTube,并获得令牌对象作为响应产生。此令牌对象有一个标记值和令牌URL作为其成员。

The API works in two steps, in the first step we need to create an Video object with all the metadata like title,tags,description, category etc. Then we need to send a request with this object to YouTube and get a Token object generated as a response. This token object has a Token Value and a Token URL as its members.

在第二个步骤,他们建议我们应该创建设置为令牌URL action属性表单。这种形式应该有一个文件上传控制和Token值作为其值的隐藏字段。当这种形式的发布,将视频上传到YouTube。

In second step they suggest that we should create a Form with the action attribute set to the Token URL. This form should have a file upload control and a hidden field with the Token Value as its value. When this form is posted, it would upload the video to YouTube.

这个伟大的工程,如果我们把它作为一个两个步骤,要求元数据用户至上,然后重定向他们第二页为实际的视频上传。然而,我们试图在一个单一的页来完成此,表现为一个单一的步骤给用户。

This works great if we have it as a two step process, asking users for the metadata first and then redirecting them on to second page for the actual video upload. However, we are trying to accomplish this in a single page, appearing as a single step to the user.

我们有一个母版的aspnetForm'这个规定,因为其中我们不能有 RUNAT =服务器属性的另一种形式。

We have a MasterPage with the 'aspnetForm' specified in it, because of which we cant have another form with runat='server' property.

我们已经尝试修改使用JavaScript / code-背后的aspnetFrom的action属性,但它保持不变,无论我们做什么。

We have tried modifying the aspnetFrom's action attribute using JavaScript/code-behind but it stays the same, whatever we do.

我们也试图与接收令牌把另一个嵌套形式,其作用标签将是对按钮的单击事件设置,从YouTube的第一反应之后。但即使这样也不行,因为在这个方法被调用的时候不创建形式。

We have also tried to put another nested form, whose action tag would be set on the button click event, after the first response from YouTube with token is received. But even this doesn't work, as the form isn't created at the time this method is called..

我们尝试了好几种方法,但没有一个似乎工作..有这方面的建议将是巨大的。

We have tried several approaches but none seems to work.. any suggestions on this would be great.

如果您有任何更多的问题,认清形势..请让我知道..

If you have any more questions to understand the situation clearly.. please let me know..

更新:

感谢您的答复家伙。

我们改变了商业逻辑,一点点解决问题。这是长回来了,我不是在寻找一个分辨率为现在..

We changed the business logic a little bit to resolve the issue. It was long back and I am not looking for a resolution as of now..

然而,问题仍然是开放的,并得到响应。我真的AP preciate各方面的帮助,因此,会离开的问题打开的任何进一步的讨论。

However, the question is still open and getting responses. I really appreciate all the help and hence, would leave the question open for any further discussions.

推荐答案

我想创建一个你要显示与元数据和视频文件上传控制文本字段用户的表单。

I would create a form that you display to the user with text fields for the metadata and a file upload control for the video.

然后在code处理回发,您可以提交元数据关至YouTube API来获取Token值。

Then in the code that handles the postback, you can submit the metadata off to the YouTube API to get the Token Value.

您再一个工艺 HttpWebRequest的与令牌值传递到创建的WebRequest 对象的方法,并设置方法属性发表。然后,添加上传的视频(见<一href=\"http://stackoverflow.com/questions/566462/upload-files-with-httpwebrequest-multipart-form-data/567460#567460\">dr邪恶的回答上传文件,HttpWebRequest的(的multipart / form-data的)通过了了解散步),当你调用的GetResponse()您文件将被提交。

You then craft an HttpWebRequest with the Token Value passed into the Create method of the WebRequest object and set the Method property to Post. You then add the uploaded video (see dr evil's answer to "Upload files with HTTPWebrequest (multipart/form-data)" for more a walk through of that), and when you call GetResponse() your file will be submitted.

事情需要提防:


  1. ScriptTimeout :如果你允许你的用户大文件上传到YouTube - 如果它需要一段时间,为您传递它,那么你的脚本可以终止prematurely。

  2. 带宽:你必须同时上传到你的服务器,然后上传到YouTube占到 - 通过允许用户直接在两个步骤上传到YouTube,你从来没有接触的视频,它永远不会接近您的服务器 - 这可能是您或您的托管服务提供商的问题 - 例如,我的主机不通过FTP在我每月的带宽流量计算,但包括上传/文件通过网站下载

  1. ScriptTimeout: If you're allowing your users to upload large files to YouTube - if it takes a while for you to transmit it, then your script could be terminated prematurely.
  2. Bandwidth: You'll have both the upload to your servers and then the upload to YouTube to account for - by allowing the user to upload directly to YouTube in a two step process you never touch the video, and it never goes near your servers - this might be an issue for you or your hosting provider - for example, my host doesn't count traffic through FTP in my monthly bandwidth, but does include files uploaded/downloaded through the website.

这篇关于YouTube的API集成ASP.NET - 上传视频单页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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