Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. [HttpPost]
  2. [ValidateAntiForgeryToken]
  3. public ActionResult Create([Bind(Include = "PostId,Title,Description,URL")] Post post, System.Web.Mvc.FormCollection collection, HttpPostedFileBase file)
  4. {
  5. if (ModelState.IsValid)
  6. {
  7. db.Posts.Add(post);
  8. YouTubeRequestSettings settings;
  9. YouTubeRequest request;
  10. string devkey = "mykey";
  11. string username = "mymail@gmail.com";
  12. string password = "mypass";
  13. var fileName = Path.GetFileName(file.FileName);
  14. var path = Path.Combine(Server.MapPath("~/Content/Videos"), fileName);
  15. file.SaveAs(path);
  16. string filepath = Path.GetFullPath(path);
  17. settings = new YouTubeRequestSettings("Clave de API 1", devkey, username, password) { Timeout = 999999999 };
  18. request = new YouTubeRequest(settings);
  19. Video video = new Video();
  20. video.Title = fileName;
  21. video.Description = "Sample Video Description";
  22. video.Tags.Add(new MediaCategory("Comedy", YouTubeNameTable.CategorySchema));
  23. video.Keywords = "Comedy";
  24. video.Private = false;
  25. video.MediaSource = new MediaFileSource(filepath, "video/");
  26. Video createdVideo = request.Upload(video);
  27. return RedirectToAction("Create");
  28.  
  29. db.SaveChanges();
  30. return RedirectToAction("Index");
  31. }
  32.  
  33. return View(post);
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement