Configuration for File Resource Type¶
JasperReports Server allows to configure validators for files uploaded in the repository.
While adding a file resource, you can only upload the files that are defined in the JasperReports Server repository. Only a valid file type (file type defined in JasperReports Server) and its corresponding file extension for that file type can be uploaded.
For more information on the list of allowed file types, see File Resource Types.
To configure the file resource type:
-
Open the configuration file
…/WEB-INF/flows/fileResourceBeans.xmlfor editing. -
Locate the
whitelistFileExtRegexByTypein the following file.<util:map id="whitelistFileExtRegexByType"> <entry key="accessGrantSchema" value="(.*\.(xml))"/> <entry key="css" value="(.*\.(css))"/> <entry key="font" value="(.*\.(ttf))"/> <entry key="img" value="(.*\.(jpg|jpeg|gif|bmp|png))"/> <entry key="jar" value="(.*\.(jar))"/> <entry key="jrxml" value="(.*\.(jrxml))"/> <entry key="olapMondrianSchema" value="(.*\.(xml))"/> <entry key="prop" value="(.*\.(properties))"/> <entry key="jrtx" value="(.*\.(jrtx))"/> <entry key="xml" value="(.*\.(xml|agxml))"/> <entry key="config" value="(.*\.(config))"/> <entry key="cer" value="(.*\.(p12|pfx))"/> <entry key="contentResource" value="(.*\.(docx|doc|ppt|pptx|xls|xlsx|ods|odt|odp|pdf|rtf|html|txt|csv|json))"/> <entry key="secureFile" value="^.+$"/> <entry key="mongoDbSchema" value="(.*\.(json))"/> <entry key="key" value="(.*\.(key))"/> <entry key="pub" value="(.*\.(pub))"/> <entry key="ppk" value="(.*\.(ppk))"/> </util:map>This map contains JasperReports Server repository file types mapping to file extensions. For example,
contentResourceis a file type in the JasperReports Server repository that is used to describe generated report outputs and some data sources, like CSV and JSON. When you upload content resource, only files with these extensions are allowed. At the same time, you cannot upload.jsonor.csvfiles as CSS or config files. Therefore, ensure that the correct file extension is set for the file that is chosen to be uploaded to the JasperReports Server repository. -
Locate the
fileNameRegexpproperty in the same file.<property name="fileNameRegexp" value="(.*\.(docx|doc|ppt|pptx|xls|xlsx|ods|odt|odp|pdf|rtf|html|txt|csv|json|xml|agxml|css|ttf|jpg|jpeg|gif|bmp|png|jrxml|jrtx|properties|config|p12|pfx|key|pub|ppk|jar))"/>The
fileNameRegexpis a regular expression rule that defines the list of file extensions allowed to be uploaded. When uploading a file, first, this validation check has to pass, and then the next check is performed to verify if the file matches the corresponding file extension present in themap: whitelistFileExtRegexByType.If the file extension does not match the allowed file types, then an error message is returned.