7.3.7. File-Selection Parameter

The file selection parameter provides users with the means to select or upload one or more files that can then go into the report generation process. This is especially useful, when working with custom script reports or export targets that can make use of such additional information.

The main configuration of the file upload parameter is to specify where files are coming from. This can either be from a TeamSpace or the internal file server, or via uploads. Additionally, you can specify a minimum and maximum number of files, as well as allowed file extensions and a maximal file size. Via the option "enable file download" you can control whether or not users can download files that have been selected.

When working with script reports you can access files that were selected via the parameter instance. In the following example we assume that we have a selection parameter with key selectionParameterKey. The script shows the various ways to access the files. For further information on scripting have a look at Chapter 16. and the ReportServer Scripting Guide.

import net.datenwerke.rs.base.ext.service.parameters.fileselection.SelectedParameterFile
import net.datenwerke.rs.base.ext.service.parameters.fileselection.UploadedParameterFile
import net.datenwerke.rs.core.service.reportmanager.entities.reports.Report;
import net.datenwerke.rs.fileserver.service.fileserver.entities.FileServerFile
import net.datenwerke.rs.scheduleasfile.service.scheduleasfile.entities.ExecutedReportFileReference;
import net.datenwerke.rs.tsreportarea.service.tsreportarea.entities.AbstractTsDiskNode
import net.datenwerke.rs.tsreportarea.service.tsreportarea.entities.TsDiskFolder;
import net.datenwerke.rs.tsreportarea.service.tsreportarea.entities.TsDiskReportReference;
import net.datenwerke.rs.tsreportarea.service.tsreportarea.entities.TsDiskRoot;

 * the parameter instance is if type net.datenwerke.rs.base.ext.service.parameters.fileselection.FileSelectionParameterInstance
 * its value is a List of net.datenwerke.rs.base.ext.service.parameters.fileselection.SelectedParameterFile 

List<SelectedParameterFile> files = parameterMap['selectionParameterKey'];

for(SelectedParameterFile file : files){

	 * A SelectedParameterFile contains an object from one of these sources
	 * Upload
	 * Teamspace
	 * Fileserver
	/* there are some common properties */
	String filename = file.getName();
	byte[] fileContent = file.getContent(); // returns null for objects without content; variants, folders
	/* and some for which you need to access the wrapped object */ 
	Object fileObject = file.getSelectedFile();
	/* when accessing the wrapped object you need to differentiate different types of content*/
	if(fileObject instanceof UploadedParameterFile){
		/* uploaded file */
		UploadedParameterFile uploadedFile = fileObject;
		/* has nothing but getContent() */
	}else if(fileObject instanceof AbstractTsDiskNode){
		/* selected from teamspace */
		AbstractTsDiskNode tsObject = fileObject;
		/* can be one of */
		if(tsObject instanceof TsDiskRoot){
			/* a teamspace root folder */
			TsDiskRoot tsRoot = tsObject;
		}else if(tsObject instanceof TsDiskFolder){
			/* a teampsace folder */
			TsDiskFolder tsFolder = tsObject;
		}else if(tsObject instanceof ExecutedReportFileReference){
			/* a reference to an executed report */
			ExecutedReportFileReference tsFileRef = tsObject;
		}else if(tsObject instanceof TsDiskReportReference){
			/* a reference to a report/variant */
			TsDiskReportReference tsReportRef = tsObject;
			Report report = tsReportRef.getReport(); 
	}else if(fileObject instanceof FileServerFile){
		/* selected from file server */