private async Task <DocumentAssetFile> GetDocumentAssetFile(int assetId) { DocumentAssetFile file = null; try { var query = new GetDocumentAssetFileByIdQuery(assetId); file = await _queryExecutor.ExecuteAsync(query); } catch (FileNotFoundException ex) { // If the file exists but the file has gone missing, log and return a 404 _logger.LogError(0, ex, "Document Asset exists, but has no file: {0}", assetId); } return(file); }
public ActionResult File(int assetId, string fileName, string extension) { DocumentAssetFile file = null; try { file = _queryExecutor.GetById <DocumentAssetFile>(assetId); } catch (FileNotFoundException ex) { // If the file exists but the file has gone missing, log and return a 404 _errorLoggingService.Log(ex); } if (file == null) { return(FileAssetNotFound("File not found")); } return(File(file.ContentStream, file.ContentType, file.FileName)); }
public async Task <ActionResult> File(int assetId, string fileName, string extension) { DocumentAssetFile file = null; try { var query = new GetDocumentAssetFileByIdQuery(assetId); file = await _queryExecutor.ExecuteAsync(query); } catch (FileNotFoundException ex) { // If the file exists but the file has gone missing, log and return a 404 _logger.LogError(0, ex, "Document Asset exists, but has no file: {0}", assetId); } if (file == null) { return(FileAssetNotFound("File not found")); } return(File(file.ContentStream, file.ContentType, file.FileName)); }
private ActionResult ValidateDocumentFileRequest(long fileStamp, string verificationToken, string fileName, DocumentAssetFile file, bool isDownload) { // additionally check that filestamp is not after the curent update date if (file == null || !IsFileStampValid(fileStamp, file.FileUpdateDate) || file.VerificationToken != verificationToken) { return(FileAssetNotFound("Document file not found")); } // if the title or filestamp is different, redirect to the correct url var sluggedFileName = SlugFormatter.ToSlug(file.FileName); if (sluggedFileName != fileName || fileStamp.ToString() != file.FileStamp) { var url = isDownload ? _documentAssetRouteLibrary.DocumentAssetDownload(file) : _documentAssetRouteLibrary.DocumentAsset(file); return(RedirectPermanent(url)); } return(null); }