public ActionResult Index(string token) { if (string.IsNullOrEmpty(token)) return Json(new { userToken = token, status = "failed", error = "invalid token" }, JsonRequestBehavior.AllowGet); var fileManager = new FileManager(UploadDirectory()); var userFiles = fileManager.GetUserFiles(token); Task.Factory.StartNew(() => fileManager.DeleteFiles(token)); return Json(new { userToken = token, userFiles }, JsonRequestBehavior.AllowGet); }
public ActionResult Upload(string token) { try { if (!TokenManager.IsValidToken(token)) return Json(new { userToken = token, status = "failed", error = "invalid token" }); var fileManager = new FileManager(UploadDirectory()); Task.Factory.StartNew(() => fileManager.DeleteFiles(token)); var keys = Request.Files.Keys.Cast<string>().ToList(); if (keys.Any(c => Request.Files[c] == null || Request.Files[c].ContentLength == 0)) { return Json(new { userToken = token, status = "failed", error = "zero length document encountered" }); } foreach (var key in keys.Where(c => Request.Files[c] != null)) { var fileName = Path.GetFileName(Request.Files[key]?.FileName); fileManager.SaveFileStream(token, fileName, Request.Files[key]?.InputStream); } return Json(new { userToken = token, status = "success!" }); } catch (Exception ex) { return Json(new { userToken = token, status = "failed", error = ex.Message }); } }