Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [HttpPost]
- [ValidateAntiForgeryToken]
- public ActionResult Create([Bind(Include = "PostId,Title,Description,URL")] Post post, System.Web.Mvc.FormCollection collection, HttpPostedFileBase file)
- {
- if (ModelState.IsValid)
- {
- db.Posts.Add(post);
- YouTubeRequestSettings settings;
- YouTubeRequest request;
- string devkey = "mykey";
- string username = "mymail@gmail.com";
- string password = "mypass";
- var fileName = Path.GetFileName(file.FileName);
- var path = Path.Combine(Server.MapPath("~/Content/Videos"), fileName);
- file.SaveAs(path);
- string filepath = Path.GetFullPath(path);
- settings = new YouTubeRequestSettings("Clave de API 1", devkey, username, password) { Timeout = 999999999 };
- request = new YouTubeRequest(settings);
- Video video = new Video();
- video.Title = fileName;
- video.Description = "Sample Video Description";
- video.Tags.Add(new MediaCategory("Comedy", YouTubeNameTable.CategorySchema));
- video.Keywords = "Comedy";
- video.Private = false;
- video.MediaSource = new MediaFileSource(filepath, "video/");
- Video createdVideo = request.Upload(video);
- return RedirectToAction("Create");
- db.SaveChanges();
- return RedirectToAction("Index");
- }
- return View(post);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement