public ActionResult Upload() { if (_securityService.CurrentUser.UserType != Core.Domain.UserTypes.Admin) { return(Json(new { ok = false, message = "No access." })); } string name = Request["report_name"]; string service = Request["service"]; var response = new FileUploadResponse(); var file = Request.Files[0]; byte[] bytes = new byte[file.ContentLength]; file.InputStream.Read(bytes, 0, bytes.Length); bool ok = _reportingService.UploadReport(service, name, bytes); if (ok) { response.files.Add(new FileUploadResponse.File() { name = file.FileName, size = file.ContentLength }); return(Json(response)); } else { Response.StatusCode = 500; return(Json(new { ok = false, message = "Upload failed" })); } }
public ActionResult Upload() { var response = new FileUploadResponse(); foreach (string filename in Request.Files) { var file = Request.Files[filename]; var stat = _fileService.CanUpload(file.FileName, file.ContentLength); if (stat == CanUploadStatus.FileTypeNotAllowed) { throw new Exception("Files of this type are not allowed."); } else if (stat == CanUploadStatus.DiskUsageLimitExceeded) { throw new Exception("Disk usage limit exceeded."); } Guid id = _fileService.StoreFileContent(file.InputStream); var f = new File() { FileName = System.IO.Path.GetFileNameWithoutExtension(file.FileName), ContentType = file.ContentType, ContentPath = id.ToString(), Extension = System.IO.Path.GetExtension(file.FileName), Size = file.ContentLength }; EntityUpdate create = new EntityUpdate(f); var result = _entityService.Update(create); if (result.Success) { response.files.Add(new FileUploadResponse.File() { id = create.Id.Value, name = file.FileName, size = file.ContentLength, url = Url.Action("Download") + "?id=" + create.Id.Value }); } } //System.Threading.Thread.Sleep(500); return(Json(response)); }
public ActionResult Upload() { var response = new FileUploadResponse(); foreach (string filename in Request.Files) { var file = Request.Files[filename]; var stat = _fileService.CanUpload(file.FileName, file.ContentLength); if (stat == CanUploadStatus.FileTypeNotAllowed) throw new Exception("Files of this type are not allowed."); else if(stat == CanUploadStatus.DiskUsageLimitExceeded) throw new Exception("Disk usage limit exceeded."); Guid id = _fileService.StoreFileContent(file.InputStream); var f = new File() { FileName = System.IO.Path.GetFileNameWithoutExtension(file.FileName), ContentType = file.ContentType, ContentPath = id.ToString(), Extension = System.IO.Path.GetExtension(file.FileName), Size = file.ContentLength }; EntityUpdate create = new EntityUpdate(f); var result = _entityService.Update(create); if (result.Success) { response.files.Add(new FileUploadResponse.File() { id = create.Id.Value, name = file.FileName, size = file.ContentLength, url = Url.Action("Download") + "?id=" + create.Id.Value }); } } //System.Threading.Thread.Sleep(500); return Json(response); }
public ActionResult Upload() { if (_securityService.CurrentUser.UserType != Core.Domain.UserTypes.Admin) { return Json(new { ok = false, message = "No access." }); } string name = Request["report_name"]; string service = Request["service"]; var response = new FileUploadResponse(); var file = Request.Files[0]; byte[] bytes = new byte[file.ContentLength]; file.InputStream.Read(bytes, 0, bytes.Length); bool ok = _reportingService.UploadReport(service, name, bytes); if (ok) { response.files.Add(new FileUploadResponse.File() { name = file.FileName, size = file.ContentLength }); return Json(response); } else { Response.StatusCode = 500; return Json(new { ok = false, message = "Upload failed" }); } }