public ActionResult GetResourceWithMime(AttachmentQueryViewModel viewModel) { if (viewModel.KeyID != null) { viewModel.AttachmentID = viewModel.DecryptKeyValue(); } else if (viewModel.HKeyID != null) { viewModel.AttachmentID = viewModel.DecryptHexKeyValue(); } var item = models.GetTable <Attachment>().Where(a => a.AttachmentID == viewModel.AttachmentID).FirstOrDefault(); if (item != null) { if (System.IO.File.Exists(item.StoredPath)) { return(File(item.StoredPath, MimeMapping.GetMimeMapping(Path.GetFileName(item.StoredPath)))); } } return(new EmptyResult()); }
public ActionResult GetResourceWithMime(AttachmentQueryViewModel viewModel) { if (viewModel.KeyID != null) { viewModel.AttachmentID = viewModel.DecryptKeyValue(); } else if (viewModel.HKeyID != null) { viewModel.AttachmentID = viewModel.DecryptHexKeyValue(); } var item = models.GetTable <Attachment>().Where(a => a.AttachmentID == viewModel.AttachmentID).FirstOrDefault(); if (item != null) { if (System.IO.File.Exists(item.StoredPath)) { new FileExtensionContentTypeProvider().TryGetContentType(item.StoredPath, out string contentType); return(new PhysicalFileResult(item.StoredPath, contentType ?? "application/octet-stream")); } } return(new EmptyResult()); }