we are trying to use the Google YouTube API to upload videos from our website to YouTube through the browser directly.
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.
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.
We have a MasterPage with the ‘aspnetForm’ specified in it, because of which we cant have another form with
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..
Thanks for the responses guys.
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..
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.
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
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.
Then in the code that handles the postback, you can submit the metadata off to the YouTube API to get the Token Value.
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.
Things to watch out for:
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.
- 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.
You could post to the YouTube form programatically. I recently modified the example found at http://www.codeproject.com/KB/cs/uploadfileex.aspx to write some code that posted a file to a third party website as a nightly job.
This would involve a performance hit as the file would have to be uploaded to your server and then to YouTube instead of directly to YouTube, but it is an option.