|  |  | 
          
            | ก่อนอื่นต้องบอกก่อนว่า มันคือ Asp.net c# core เป็น youtube โดยที่ User ไม่ต้องหารูปมาแยก Upload รูปภาพโดยมีการ Coding ดังต่อไปนี้ 
 ต้องเรียกใช้งานตัวนี้ด้วยน่ะครับ
 
 #using ImageResizer;
 
 Code (ASP)
 
 [HttpPost]
        public async Task<IActionResult> AddVideo(Videos model, IFormFile FileName)
        {
            string msg = "";
            try
            {
                if(model.IsStreaming == false)
                {
                    if (FileName != null && FileName.Length > 0)
                    {
                        var uploads = Path.Combine(_environment.WebRootPath.ToString(), "uploads/video/");
                        if (FileName.Length > 0)
                        {
                            string fileName = ContentDispositionHeaderValue.Parse(FileName.ContentDisposition).FileName.Trim('"');
                            string UniqueFileName = string.Format(@"{0}", Guid.NewGuid()) + fileName.ToString();
                            using (var fileStream = new FileStream(Path.Combine(uploads, UniqueFileName), FileMode.Create))
                            {
                                await FileName.CopyToAsync(fileStream);
                            }
                            model.FileName = UniqueFileName.ToString();
                            var ffMpeg = new NReco.VideoConverter.FFMpegConverter();
                            ffMpeg.GetVideoThumbnail(Path.Combine(uploads, UniqueFileName), uploads + UniqueFileName + ".jpg", 10);
                            model.Thumnail = UniqueFileName + ".jpg";
                        }
                    }
                }else
                {
                    var youtubeIds = model.Url.Split('=');
                    var uploads = Path.Combine(_environment.WebRootPath.ToString(), "uploads/video/");
                    string UniqueFileName = string.Format(@"{0}", Guid.NewGuid()+ ".jpg");
                    using (WebClient client = new WebClient())
                    {
                        client.DownloadFileAsync(new Uri("https://img.youtube.com/vi/"+ youtubeIds[1] + "/0.jpg"), Path.Combine(uploads, UniqueFileName));
                    }
                    model.Url = "https://www.youtube.com/embed/" + youtubeIds[1];
                    model.Thumnail = UniqueFileName;
                }
                
                DB.Videos.Add(model);
                await DB.SaveChangesAsync();
                msg = "บันทึกข้อมูลสำเร็จ";
            }
            catch (Exception e)
            {
                msg = "Error is :" + e.InnerException.Message;
                return Json(new { valid = false, message = msg, type = model.VideoCategoryId });
            }
            return Json(new { valid = true, message = msg, type = model.VideoCategoryId });
        }
 
 
 Tag : ASP, Ms SQL Server 2016, jQuery, Web (ASP.NET), MVC, C#
 
 
 |  
            | 
 ประวัติการแก้ไข
 2017-06-23 12:01:40
 |  
            | 
              
                |  |  |  |  
                |  | 
                    
                      | Date :
                          2017-06-23 12:00:06 | By :
                          bunchuai | View :
                          897 | Reply :
                          1 |  |  |  
                |  |  |  |  |  
            |  |  
		            |  |