public async Task <string> CopyMedia([FromBody] MediaCategory objMediaCategory) { string message = string.Empty; MediaSettingController mediaSettingController = new MediaSettingController(); MediaSettingKeys mediaSettingKeys = await mediaSettingController.GetMediaSettingKeyValue(); string[] extensions = { }; string rootPath = MediaHelper.GetRootPath(mediaSettingKeys, objMediaCategory, out extensions); if (objMediaCategory.UploadType == "category") { if (objMediaCategory.BaseCategory.ToLower().IndexOf(rootPath.ToLower()) > -1 && objMediaCategory.ParentCategory.ToLower().IndexOf(rootPath.ToLower()) > -1) { message = MediaHelper.CopyMediaCategory(objMediaCategory.BaseCategory, objMediaCategory.ParentCategory); } } else { if (objMediaCategory.BaseCategory.ToLower().IndexOf(rootPath.ToLower()) > -1 && objMediaCategory.ParentCategory.ToLower().IndexOf(rootPath.ToLower()) > -1) { message = MediaHelper.CopyMediaFile(objMediaCategory.BaseCategory, objMediaCategory.ParentCategory); } } return(message); }
public async Task <IActionResult> GetMediaByPath(string basePath, string filter) { MediaSettingController mediaSettingController = new MediaSettingController(); MediaSettingKeys mediaSetting = await mediaSettingController.GetMediaSettingKeyValue(); return(ViewComponent("MediaImages", new { folderName = basePath, filterText = filter, mediaSettingKeys = mediaSetting })); }
public async Task <JsonResult> GetMediaFolderList(MediaCategory mediaCategory) { MediaSettingController mediaSettingController = new MediaSettingController(); MediaSettingKeys mediaSettingKeys = await mediaSettingController.GetMediaSettingKeyValue(); string folderList = MediaHelper.GetMediaFolderList(mediaCategory, mediaSettingKeys); return(Json(folderList)); }
public async Task <IViewComponentResult> InvokeAsync() { AddJS("MediaManagement", "/cbuilderassets/js/SageMediaManagement.js"); AddCSS("MediaMgmt", "/cbuilderassets/css/MediaManagement.css"); MediaLibraryInfo libraryInfo = new MediaLibraryInfo(); MediaCategory mediaCategory = new MediaCategory(); //Get Username here later MediaSettingController settingController = new MediaSettingController(); MediaSettingKeys mediaSettingKeys = await settingController.GetMediaSettingKeyValue(); libraryInfo.MediaSettingKeys = mediaSettingKeys; libraryInfo.MediaFolderList = MediaHelper.GetMediaFolderList(mediaCategory, mediaSettingKeys); PackMediaJs(); return(await Task.FromResult((IViewComponentResult)View("Default", libraryInfo))); }
public async Task <string> MoveMedia([FromBody] MediaCategory objMediaCategory) { string message = string.Empty; MediaSettingController mediaSettingController = new MediaSettingController(); MediaSettingKeys mediaSettingKeys = await mediaSettingController.GetMediaSettingKeyValue(); string[] extensions = { }; string rootPath = MediaHelper.GetRootPath(mediaSettingKeys, objMediaCategory, out extensions); if (objMediaCategory.BaseCategory.ToLower() != objMediaCategory.ParentCategory.ToLower()) { if (objMediaCategory.UploadType == "category") { if (objMediaCategory.BaseCategory.ToLower().IndexOf(rootPath.ToLower()) > -1 && objMediaCategory.ParentCategory.ToLower().IndexOf(rootPath.ToLower()) > -1) { message = MediaHelper.MoveMediaCategory(objMediaCategory.BaseCategory, objMediaCategory.ParentCategory); MediaHelper.MoveMediaFile(MediaHelper.originalThumbPath + objMediaCategory.BaseCategory, MediaHelper.originalThumbPath + objMediaCategory.ParentCategory); MediaHelper.MoveMediaFile(MediaHelper.largeThumbPath + objMediaCategory.BaseCategory, MediaHelper.largeThumbPath + objMediaCategory.ParentCategory); MediaHelper.MoveMediaFile(MediaHelper.mediumThumbPath + objMediaCategory.BaseCategory, MediaHelper.mediumThumbPath + objMediaCategory.ParentCategory); } } else { if (objMediaCategory.BaseCategory.ToLower().IndexOf(rootPath.ToLower()) > -1 && objMediaCategory.ParentCategory.ToLower().IndexOf(rootPath.ToLower()) > -1) { message = MediaHelper.MoveMediaFile(objMediaCategory.BaseCategory, objMediaCategory.ParentCategory); string ext = MediaHelper.GetFileExtension(objMediaCategory.BaseCategory); if (ext == "jpg" || ext == "png" || ext == "jpeg") { MediaHelper.MoveMediaFile(MediaHelper.originalThumbPath + objMediaCategory.BaseCategory, MediaHelper.originalThumbPath + objMediaCategory.ParentCategory); MediaHelper.MoveMediaFile(MediaHelper.largeThumbPath + objMediaCategory.BaseCategory, MediaHelper.largeThumbPath + objMediaCategory.ParentCategory); MediaHelper.MoveMediaFile(MediaHelper.mediumThumbPath + objMediaCategory.BaseCategory, MediaHelper.mediumThumbPath + objMediaCategory.ParentCategory); } } } } return(message); }
public JsonResult FileUpload(IFormFile files, string fileextension, string rootPath, string quality, string type) { string retMsg = "0###fail"; try { bool isValidFile = false; string validExtension = string.Empty; string retFilePath = string.Empty; string dirBaseLocation = string.Empty; string originalPath = string.Empty; string thumbLargePath = string.Empty; string thumbMediumPath = string.Empty; string thumbSmallPath = string.Empty; string strBaseLocation = rootPath; string filename = string.Empty; string newFileName = string.Empty; // HttpRequest Request = HttpContext.Current.Request; string fileExt = fileextension.ToString(); string[] allowExtensions = fileExt.Split(','); long encodeQuality = 10L; if (quality != null && quality.ToString().Length > 0) { long.TryParse(quality, out encodeQuality); } if (files != null) { MediaSettingKeys objsettingInfo = new MediaSettingKeys(); MediaSettingController objController = new MediaSettingController(); objsettingInfo = objController.GetMediaSettingKeyValue().Result; if (objsettingInfo != null) { string ext = string.Empty; switch (type) { case "image": ext = objsettingInfo.ImageExtension; break; case "video": ext = objsettingInfo.VideoExtension; break; case "document": ext = objsettingInfo.DocumentExtension; break; default: ext = objsettingInfo.ImageExtension + "," + objsettingInfo.VideoExtension + "," + objsettingInfo.DocumentExtension; break; } allowExtensions = ext.Split(','); if (string.IsNullOrEmpty(fileExt)) { fileExt = ext; } } string extension = GetExtension(files.FileName.ToLower()).ToLower(); if (IsValidExtension(allowExtensions, extension)) { string[] myExtensions = fileExt.Split(','); if (IsValidExtension(myExtensions, extension)) { isValidFile = true; retMsg = "0###Valid file Extension"; } else { isValidFile = false; retMsg = "0###Not valid file Extension"; } } else { isValidFile = false; retMsg = "0###Not valid file Extension"; } if (isValidFile) { filename = Path.GetFileName(files.FileName.Replace(" ", "_")); originalPath = Path.Combine(_hostingEnvironment.WebRootPath, MediaHelper.originalThumbPath, strBaseLocation); string tempPath = Path.Combine(_hostingEnvironment.WebRootPath, MediaHelper.tempThumbPath, strBaseLocation); thumbLargePath = Path.Combine(_hostingEnvironment.WebRootPath, MediaHelper.largeThumbPath, strBaseLocation); thumbMediumPath = Path.Combine(_hostingEnvironment.WebRootPath, MediaHelper.mediumThumbPath, strBaseLocation); string baseLocationPath = Path.Combine(_hostingEnvironment.WebRootPath, strBaseLocation); newFileName = MediaHelper.NewFileName(filename.ToLower(), baseLocationPath); string screenshotPath = string.Empty; if (!Directory.Exists(originalPath)) { Directory.CreateDirectory(originalPath); } if (!Directory.Exists(thumbLargePath)) { Directory.CreateDirectory(thumbLargePath); } if (!Directory.Exists(thumbMediumPath)) { Directory.CreateDirectory(thumbMediumPath); } if (!Directory.Exists(baseLocationPath)) { Directory.CreateDirectory(baseLocationPath); } if (!Directory.Exists(tempPath)) { Directory.CreateDirectory(tempPath); } thumbLargePath = Path.Combine(thumbLargePath, newFileName); thumbMediumPath = Path.Combine(thumbMediumPath, newFileName); originalPath = Path.Combine(originalPath, newFileName); tempPath = Path.Combine(tempPath, newFileName); string filePath = Path.Combine(baseLocationPath, newFileName); retFilePath = retFilePath + filename + ','; bool isImage = CheckImage(extension, objsettingInfo.ImageExtension); if (isImage) { ImageOptimize objOptimizeImage = new ImageOptimize(); using (FileStream tempPath1 = System.IO.File.Create(tempPath)) files.CopyTo(tempPath1); // files.SaveAs(tempPath); objOptimizeImage.OptimizeImage(_hostingEnvironment.WebRootPath, tempPath, strBaseLocation, newFileName, extension); } else { using (FileStream tempPath1 = System.IO.File.Create(this.GetPathAndFilename(filename))) files.CopyTo(tempPath1); //files.SaveAs(filePath); } retMsg = "1###" + retFilePath.TrimEnd(',').Replace("." + extension, "").Replace("_", " ") + "###" + newFileName; } } } catch (Exception ex) { ex.ToString().WriteLOG(); throw; } //string filename = ContentDispositionHeaderValue.Parse(files.ContentDisposition).FileName.Trim('"'); //filename = this.EnsureCorrectFilename(filename); //using (FileStream output = System.IO.File.Create(this.GetPathAndFilename(filename))) // files.CopyTo(output); return(this.Json(retMsg)); }