public JsonResult GetFileUploadInfo() { var uploadInfoViewModel = new UploadInfoViewModel { DirectoryTempUpload = UploadHelper.GetDirectoryTempPath(), MaxRequestLengthInBytes = UploadHelper.GetMaxRequestLengthInBytes(), FileCount = UploadHelper.GetFileCountInUploadDirectoryTemp(), FilesLengthInBytes = UploadHelper.GetFilesInUploadDirectoryTemp().Sum(c => c.Length) }; return(Json(uploadInfoViewModel, JsonRequestBehavior.AllowGet)); }
public async Task <IActionResult> Upload(UploadInfoViewModel fileInfo) { string userEmail = HttpContext.GetUserEmail(); if (!String.IsNullOrEmpty(userEmail)) { try { var context = this.services.GetService(typeof(HGTDbContext)) as HGTDbContext; var user = context.HGTUsers.FirstOrDefault(x => x.Email == userEmail); if (user != null) { long size = fileInfo.File.Length; String ext = System.IO.Path.GetExtension(fileInfo.File.FileName); // Very immportant to check format here other anyone will upload anything var uniqueID = CreateUniqueVideoID(); var fileAddress = $"{user.Id}_{ uniqueID}{ext}"; VideoInfo videoInfo = new VideoInfo { FolderName = user.Id, FileName = $"https://s3.ap-south-1.amazonaws.com/{bucketName}/{fileAddress}", UploadDateTime = DateTime.Now, Title = fileInfo.Title, Description = fileInfo.Description, Category = fileInfo.Category, Format = ext, HGTUserID = user.Id }; UploadFileAsync(fileInfo.File, fileAddress).Wait(); context.Videos.Add(videoInfo); context.SaveChanges(); } } catch { } } // var converter = new FFMpegConverter(); // converter.ConvertMedia(filePath, filePath + "new", "mp4"); return(Ok(new { Message = "you Are successfully Logged in" })); }
// [RequestSizeLimit(1073741823)] public async Task <IActionResult> Upload([FromBody] UploadInfoViewModel fileInfo) { string userId = HttpContext.GetUserID(); if (!String.IsNullOrEmpty(userId)) { try { var context = this.services.GetService(typeof(HGTDbContext)) as HGTDbContext; if (context.Capthas.Single(x => x.Id == fileInfo.CapthaId).CapthaAnswer != fileInfo.Captha) { return(Ok(new ServiceResponse { Status = "error", Message = "Captha Answer not Matched" })); } VideoInfo videoInfo = new VideoInfo { VideoUrl = fileInfo.VideoUrl, UploadDateTime = DateTime.Now, Title = fileInfo.Title, Description = fileInfo.Description, Category = fileInfo.Category, HGTUserID = userId }; if (!String.IsNullOrEmpty(fileInfo.PosterUrl)) { var startIndex = fileInfo.PosterUrl.IndexOf("base64,"); var base64Image = fileInfo.PosterUrl.Substring(startIndex + 7); var index1 = fileInfo.PosterUrl.IndexOf('/'); var index2 = fileInfo.PosterUrl.IndexOf(';'); var ext = fileInfo.PosterUrl.Substring(index1 + 1, index2 - index1 - 1); var uniqueID = CreateUniqueVideoID(); var path = $"{userId}_{ uniqueID}.{ext}"; await this.UploadFileAsync(Convert.FromBase64String(base64Image), path); videoInfo.PosterUrl = $"https://s3.ap-south-1.amazonaws.com/{bucketName}/{path}"; } context.Videos.Add(videoInfo); var tv = context.TempVideo.FirstOrDefault(x => x.Path == fileInfo.VideoUrl); if (tv != null) { context.TempVideo.Remove(tv); } await context.SaveChangesAsync(); return(Ok(new ServiceResponse { Status = "success", Message = videoInfo.ID.ToString() })); } catch (Exception e) { this.logger.Log("Upload has Problem", e.Message, e.InnerException?.Message); return(Ok(new ServiceResponse { Status = "error", Message = "Something Went Wrong When Uploading The File" })); } } return(Ok(new ServiceResponse { Status = "error", Message = "Something Went Wrong When Uploading The File" })); }