Exemplo n.º 1
0
        private ActionResult DisplayResourceImpl(string fileResourceInfoPrimaryKey, FileResourceInfo fileResourceInfo)
        {
            if (fileResourceInfo == null)
            {
                var message = $"File Resource {fileResourceInfoPrimaryKey} Not Found in database. It may have been deleted.";
                throw new HttpException(404, message);
            }

            // If you're adding new mime types to the system, you need to add them below -- 08/29/2019 SMG
            // Removed PDFResult & ExcelResult and just ran both through the FileResourceResult to fix bugs occurring - both PDF & Excel work fine/better with FileResourceResult -- 6/15/2020 MZ
            switch (fileResourceInfo.FileResourceMimeType.ToEnum)
            {
            case FileResourceMimeTypeEnum.PDF:
            case FileResourceMimeTypeEnum.ExcelXLS:
            case FileResourceMimeTypeEnum.ExcelXLSX:
            case FileResourceMimeTypeEnum.xExcelXLSX:
            case FileResourceMimeTypeEnum.WordDOCX:
            case FileResourceMimeTypeEnum.WordDOC:
            case FileResourceMimeTypeEnum.PowerpointPPTX:
            case FileResourceMimeTypeEnum.PowerpointPPT:
            case FileResourceMimeTypeEnum.CSS:
            case FileResourceMimeTypeEnum.KMZ:
            case FileResourceMimeTypeEnum.KML:
            case FileResourceMimeTypeEnum.XZIP:
            case FileResourceMimeTypeEnum.ZIP:
                return(new FileResourceResult(fileResourceInfo.GetOriginalCompleteFileName(), fileResourceInfo.FileResourceData.Data, fileResourceInfo.FileResourceMimeType));

            case FileResourceMimeTypeEnum.XPNG:
            case FileResourceMimeTypeEnum.PNG:
            case FileResourceMimeTypeEnum.TIFF:
            case FileResourceMimeTypeEnum.BMP:
            case FileResourceMimeTypeEnum.GIF:
            case FileResourceMimeTypeEnum.JPEG:
            case FileResourceMimeTypeEnum.PJPEG:
                return(File(fileResourceInfo.FileResourceData.Data, fileResourceInfo.FileResourceMimeType.FileResourceMimeTypeName));

            default:
                // throw a more specific error that can hint to developers and assure users what needs to be done when adding a new mime type
                throw new SitkaDisplayErrorException($"The file type \"{fileResourceInfo.FileResourceMimeType.FileResourceMimeTypeDisplayName}\" has not been explicitly whitelisted to download. The development team has been notified, if you continue to receive errors, please contact support.");
            }
        }
Exemplo n.º 2
0
 public PdfResult(FileResourceInfo fileResourceInfo) : base(fileResourceInfo.GetOriginalCompleteFileName(), fileResourceInfo.FileResourceData.Data, FileResourceMimeType.PDF)
 {
     Check.Require(fileResourceInfo.FileResourceMimeType == FileResourceMimeType.PDF, "Only a real PDF file can be saved off as PDF");
     ConstructorImpl(fileResourceInfo.GetOriginalCompleteFileName());
 }