public JsonResult UploadImage(IFormFile file, PageContentTypes type, string itemid, string filename) { filename = Path.GetFileNameWithoutExtension(filename); var upload = new FormUpload(_environment.WebRootPath); if (file != null) { switch (type) { case PageContentTypes.Campaign: upload.SaveFile(file, filename, "campaign"); break; case PageContentTypes.Category: upload.SaveFile(file, filename, "categoryheader"); break; } } return(Json("OK")); }
public IActionResult Post() { if (Request.Form.ContainsKey("data")) { var uploadData = JsonConvert.DeserializeObject <UploadDataModelView>(Request.Form["data"]); if (uploadData == null) { throw new ArgumentNullException(nameof(uploadData.path), "Data is not found in upload request body!"); } if (string.IsNullOrWhiteSpace(uploadData.path)) { throw new ArgumentNullException(nameof(uploadData.path), string.Format("Parameter '{0}' is not found in upload request body!", nameof(uploadData.path))); } var savedFiles = new List <StorageFile>(); //get posted file from web form foreach (IFormFile file in Request.Form.Files) { var formUpload = new FormUpload(uploadData.path, MainCfg.AllowedImageExtensions); StorageFile savedFile = formUpload.SaveFile(file); savedFiles.Add(savedFile); } if (savedFiles.Any()) { return(Ok(savedFiles)); } } return(new BadRequestResult()); //return new StatusCodeResult(Convert.ToInt32(HttpStatusCode.BadRequest)); }