The File component

The File component allows users to upload files, and is the counterpart of the ResultFile component. In comparison to the gui_upload functionality, there are several differences.

  • The File component does not block the user interface during upload. It also does not trigger an event in the back-end.
  • For deployed applications, the file is uploaded to the webserver instead of being part of the submission data. This makes the File component suitable for uploading larger files.

File component

There are two modes of operation:

  • base64: In base64 mode, the selected files are base64 encoded and put in the submission data. This is the only available mode for local applications.
  • portal: In portal mode, the selected files are uploaded to the portal webserver. Download URLs are provided in the submission data. This is the default mode for deployed applications.

Note: the File component also offers upload capabilities for a number of cloud storage services. These are not facilitated yet.

In addition to the properties and methods listed below, this component inherits properties and methods from the superclass Component. For example, any File component has a label and tooltip property even though these are not explicitly listed here.

Properties

NameDescriptionDatatypeDefault
fileMaxSizeMaximum size allowed for files. E.g. "10MB".StringNull
fileMinSizeMinimum size allowed for files. E.g. "10KB".StringNull
filePatternPattern or MIME type for allowed file types. E.g. ".pdf,image/png"String"*"
fileTypesAllowed file types to be uploaded. Combinations of 'label', and 'value' with the filePattern.List of dicts / struct array
imageDisplay the uploaded file as image instead of the file name.BooleanFalse
imageSizeThe image display size. Allows for downscaling.StringNull
tableViewWhen true and the component is part of an EditGrid, the component's value is shown (simplified) in the collapsed row of the EditGrid.BooleanFalse
uploadOnlyWhether the files cannot be downloaded again from the File component.BooleanTrue
multipleAllow the user to upload multiple files when set to True.BooleanFalse
webcamAllow the user to take a picture with a webcam / camera.BooleanFalse
webcamSizeDisplay size for webcam images.StringNull

Methods

NameSyntaxDescription
storeUploadedFiles[payload, filePaths] = File​.storeUploadedFiles(​metaData, payload, key, Parent=parent, NestedForm=nestedForm)Use the submission data to save the files in the back-end and provide the local file paths as output1.
useBase64Uploadobj​.useBase64Upload()Use base64 mode in deployed mode.

Basic usage

  • In the guiInit function or builder add a File component and modify the properties to allow users to select the intended files types.

  • In an event callback run the File.storeUploadedFiles method to move the selected files to the back-end and make them available for your code. Note that the second output of the method contains the unique, full names to the files in the back-end1. These can directly be used to access the file contents in your back-end code. Note that the mode of operation does not affect your code.

  • (In a later event callback) you can get more information on the uploaded files by using the utils.getSubmissionData function. The function returns a list of dicts / struct array with per uploaded file:

    • name: the unique local file name1. Note that it includes a unique suffix to prevent overwriting files and that it does not contain the folder path.
    • originalName: The original name of the uploaded file. Includes the file extension. Useful when the (changed) file needs to be made available for download in a ResultFile component.
    • size: The size of the uploaded file, in bytes.
    • storage: the File component's operation mode.
    • type: file type.
  • The local files can be reached and processed in your back-end code by combining the:

    • session folder where the files are stored: sessionFolder = utils.getSessionFolder(meta_data), and
    • the local file "name" as described above.

See also

  • ResultFile for downloading files created in the back-end.

1

The files are saved in the session folder. This folder is removed when the application is closed.