Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 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. try
  9. {
  10. if (file != null)
  11. {
  12. YouTubeRequestSettings settings;
  13. YouTubeRequest request;
  14. string devkey = "mykey";
  15. string username = "mymail@gmail.com";
  16. string password = "mypass";
  17. var fileName = Path.GetFileName(file.FileName);
  18. var path = Path.Combine(Server.MapPath("~/Content/Videos"), fileName);
  19. file.SaveAs(path);
  20. string filepath = Path.GetFullPath(path);
  21. settings = new YouTubeRequestSettings("Clave de API 1", devkey, username, password) { Timeout = 999999999 };
  22. request = new YouTubeRequest(settings);
  23. Video video = new Video();
  24. video.Title = fileName;
  25. video.Description = "Sample Video Description";
  26. video.Tags.Add(new MediaCategory("Comedy", YouTubeNameTable.CategorySchema));
  27. video.Keywords = "Comedy";
  28. video.Private = false;
  29. video.MediaSource = new MediaFileSource(filepath, "video/");
  30. Video createdVideo = request.Upload(video);
  31. return RedirectToAction("Create");
  32. }
  33. }
  34. catch
  35. {
  36. return View();
  37. }
  38.  
  39. db.SaveChanges();
  40. return RedirectToAction("Index");
  41. }
  42.  
  43. return View(post);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement