Ask your technical questions on forums or here :
ASP.NET or MVC | C# | Windows Phone
Microsoft Technology Journals by Abhimanyu K Vatsa
HOME ABOUT RAZOR BOOK SPEAKING MVC ASP.NET JQUERY VIDEOS EBOOK ARCHIVE

29 Nov 2015

Upload video on YouTube in ASP.NET or MVC

In this post you will learn how to upload video on YouTube from your application. I’ve used ASP.NET Web Forms as well as MVC bits to implement all functionality easily. You can achieve similar functionality ASP.NET Web Forms or MVC alone.

Before you begin here, download the source code and replace with your client id and secret in Controller > YouTubeController.cs file.

Getting client id and secret from google console is easy, but make sure the highlighted options in below screenshot, authorized redirect url should be exact same. Note to remove localhost when going on production.




If you want to upload video on YouTube, here’s the prototype explained in 2 easy steps:

1. User will select video file and hit upload button on default.aspx page

When user will click on upload button, below code will be invoked which is written in uploadOnYouTube.js file:

$(document).ready(function () {
    $(document).on("click", "#btnVedioSubmit", uploadMetaDataYouTube);
});


2. Upon button click a new Ajax request will execute to send data into MVC Controller

Look into above script, this will invoke uploadMetaDataYouTube method which will talk to MVC Controller to upload video and get upload status.

The MVC controller will have responsibility to validate the token and get new refreshed token. This refreshed token will be stored in some DataStore, in our case this is file system. Keep in mind, when you run your application first time, this will open a new tab and ask you to grant permissions, once this happens correctly, this issue a refreshed token which gets stored. This stored refreshed token will be used in next request onwards. If you want to store refreshed token in database, please read this post http://www.daimto.com/google-oauth2-csharp/.

Once application gets the refreshed token, this will begin file upload, here’s my working code:


You will receive upload status, like Booting, Starting, uploading with progress bar, Completed.

Hope this helps.

Comment using Google Services (2 comments):

  1. How https://

    it shows

    HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

    ReplyDelete
  2. This is not working with IIS server.Any Suggestions...?

    ReplyDelete