public ActionResult Index() { ImageParameterModel imageParameter = new ImageParameterModel { AWSBucketName = "worldpipelines", //"testbucketpp", AWSBucketPath = "media/articles/", AWSSelectPath = "media/articles/thumb/", ThumbRequired = true, PopRequired = true, ThumbWidth = "165", ThumbHeight = "110", MainWidth = "240", MainHeight = "160", PopWidth = "450", PopHeight = "300", AWSThumbPath = "media/articles/thumb/", AWSMainPath = "media/articles/main/", AWSPopPath = "media/articles/pop/" }; return(View(imageParameter)); }
public string ImageUpload(ImageParameterModel data) { if (string.IsNullOrEmpty(data.FileName)) { return(string.Empty); } string fileName = string.Concat(Path.GetFileNameWithoutExtension(data.FileName), ".jpeg"); string base64 = data.Source.Substring(data.Source.IndexOf(',') + 1); base64 = base64.Trim('\0'); byte[] imgData = Convert.FromBase64String(base64); Image img = byteArrayToImage(imgData); string path = Path.Combine(Server.MapPath("~/AwsTemp"), fileName); img.Save(path); var versions = new Dictionary <string, string>(); //Define the versions to generate versions.Add("_thumb", string.Concat("maxwidth=", data.ThumbWidth, "&maxheight=", data.ThumbHeight, "&format=jpeg&speed=0&quality=90")); versions.Add("_main", string.Concat("maxwidth=", data.MainWidth, "&maxheight=", data.MainHeight, "&format=jpeg&speed=0&quality=90")); versions.Add("_pop", string.Concat("maxwidth=", data.PopWidth, "&maxheight=", data.PopHeight, "&format=jpeg&speed=0&quality=90")); //Generate each version foreach (var suffix in versions.Keys) { //Let the image builder add the correct extension based on the output file type ImageBuilder.Current.Build( new ImageJob( path, path + suffix, new Instructions(versions[suffix]), false, true)); } if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } if (data.ThumbRequired) { // Create thumbnail AwsApi.UploadFile(data.AWSBucketName, string.Concat(data.AWSThumbPath, fileName), string.Concat(path, "_thumb.jpg")); if (System.IO.File.Exists(string.Concat(path, "_thumb.jpg"))) { System.IO.File.Delete(string.Concat(path, "_thumb.jpg")); } } // Create Main AwsApi.UploadFile(data.AWSBucketName, string.Concat(data.AWSMainPath, fileName), string.Concat(path, "_main.jpg")); if (System.IO.File.Exists(string.Concat(path, "_main.jpg"))) { System.IO.File.Delete(string.Concat(path, "_main.jpg")); } if (data.PopRequired) { // Create Pop AwsApi.UploadFile(data.AWSBucketName, string.Concat(data.AWSPopPath, fileName), String.Concat(path, "_pop.jpg")); if (System.IO.File.Exists(String.Concat(path, "_pop.jpg"))) { System.IO.File.Delete(String.Concat(path, "_pop.jpg")); } } return(fileName); }