Skip to content

Instantly share code, notes, and snippets.

@yogyogi
Created June 19, 2021 13:51
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save yogyogi/cf430fdf294b0acabaaef151fb45aabc to your computer and use it in GitHub Desktop.
ASP.NET MVC BlueImp jQuery File Upload
[HttpPost]
public JsonResult Upload(HttpPostedFileBase files)
{
var resultList = new List<UploadFilesResult>();
string path = Server.MapPath("~/Content/uploads/");
files.SaveAs(path + files.FileName);
UploadFilesResult uploadFiles = new UploadFilesResult();
uploadFiles.name = files.FileName;
uploadFiles.size = files.ContentLength;
uploadFiles.type = "image/jpeg";
uploadFiles.url = "/Content/uploads/" + files.FileName;
uploadFiles.deleteUrl = "/Home/Delete?file=" + files.FileName;
uploadFiles.thumbnailUrl = "/Content/uploads/" + files.FileName;
uploadFiles.deleteType = "GET";
resultList.Add(uploadFiles);
JsonFiles jFiles = new JsonFiles(resultList);
return Json(jFiles);
}
public JsonResult Delete(string file)
{
System.IO.File.Delete(Path.Combine(Server.MapPath("~/Content/uploads/"), file));
return Json("OK", JsonRequestBehavior.AllowGet);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment