File Upload Element

The File Upload Element allows a user to upload a file to you from within the form, which can be stored as a file or in a database.

Picture showing the File Upload Element after the user has selected a file.

Click on image above to display larger

 

At runtime, the Element displays a Browse button, along with some accompanying wording and the configured maximum file size. These are contained within a box with rounded corners and a dotted boundary line, as shown above. When the user clicks or taps the Browse button, a standard file browse dialog will be displayed for the user to locate and select the required file. In addition, a file can be dragged from an opened browse dialog box and dropped anywhere inside the Element's dotted boundary line.

After selecting a file by browsing or dragging-and-dropping, the Element will change to display the name of the selected file:

Picture showing the File Upload Element after the user has selected a file.

Click on image above to display larger

 

At this point the file is not actually uploaded and the user can delete their selection by clicking or tapping the Picture showing the Close button. button to the right of the file name. Alternatively, the Clear button can be clicked to remove the selected file. The file will be removed and the Browse button (along with the accompanying wording and configured maximum file size) will be displayed. The user can then make another selection, if desired.

The file will only be uploaded when the user submits the form, using a Submit Button, a Submit form or Update Datasource action within an Event, a call to submitForm or updateDatasource within custom JavaScript or by clicking on the Pay button in a Capita Pay360 Cart Element.

 

In addition, you must provide an output mapping for the File Upload Element - see the Value property below for more information.

When the form is submitted, the selected file will be uploaded to the web server running your form and either stored in a database or written to disk.

If you want to allow users to upload more than one file, you can add as many File Upload Elements as you need to your form - each Element will only allow a single file to be uploaded. Each Element is configured separately, allowing you to mix uploading to file and to a database on the same form, if required.

 

Whether you choose to store uploaded files as files or in a database, you will need two database tables to hold information about the files uploaded and, if storing the files in a database, to store the files as well:

  • The first table must be called NDLFXFile in a Database of the same name, NDLFXFile. We will refer to this database and table as the File Upload database and the File Upload table. When your form is submitted, Digitise Forms will automatically create a record in this table for each file uploaded from the form.

    This table must contain the following three columns:

    • FileId - the Primary Key with a data type of GUID (uniqueidentifier), which will uniquely identify each uploaded file record and will be used to link this record to the corresponding record in the second table, described below,

    • Filename - which will contain the full file path and file name of the file, if the file is stored to the file system, or the file name of the file, without a file path, if the file is stored to the database. In either case, the name of the uploaded file will be changed to be a unique name in the format: <formname>_<FileId>.<fileextension>

      and

    • FileData - which will contain the actual file contents if the file is stored to the database, or NULL if the file is stored to the file system.

  •  

  • The second, or sister, table and it's parent database can have any names. Your form must be configured to create a record in this table when the form is submitted, which will include a link for each file uploaded from the form to a corresponding record in the NDLFXFile table (this will be explained further shortly). Note, that there will only be one record in this table per form submission, but there will be a separate record in the NDLFXFile table for each file uploaded as part of that submission. This table is used by the File Download Element to locate previously uploaded files if you want to allow them to be subsequently downloaded to the same or a different form.

    We recommend you use the form Dataset for this table which will allow you to include other data from the form in the one table, although you can create a separate table if your needs require it.

    The table may contain any columns but it must include the following columns:

    • A Primary Key with a data type of GUID (uniqueidentifier), which will uniquely identify each record in the table

      and

    • A separate column, with a data type of GUID (uniqueidentifier), for each File Upload Element included on the form. This column will contain the Primary Key, i.e. the value in the FieldId column, from the corresponding record for the file in the NDLFXFile table. Note, however, that whilst these columns provide the link between the files recorded in the NDLFXFile table and any other data captured from the form, which is stored in this second table, the fields do not have a Foreign Key relationship.

 

The New Datasource from Form option provides a simple method to create these tables, but you can create them separately, e.g. using SQL Server Management Studio, if you prefer. If you use New Datasource from Form, Form Studio will automatically generate the NDLFXFile Datasource and its NDLFXFile Dataset and also generate a Form Datasource and Dataset containing the required data columns for the File Upload Elements along with columns for any other Elements which aren't output mapped to another Datasource. The File Upload columns will be given the same names as the Upload Elements themselves. New Datasource from Form will also automatically output map the File Upload elements to the appropriate Form Dataset columns. When you publish the form, the physical databases and tables will be created, if they don't already exist. If you are not using New Datasource from Form for any other data on the form, you can still use it to create the Datasets required for the File Upload Element(s). If you don't use New Datasource from Form to create the Datasets, you will have to manually output map the Upload Element(s) to the appropriate column(s) in the sister Dataset (see the Value property below).

Once you have created these Datasources and Datasets, you can view them in the Datasources tab of the Project Explorer as normal. Note, however, that if you use New Datasource from Form to generate the tables, the NDLFXFile Dataset will be greyed-out and cannot be opened or edited, although it can be deleted if no longer required or you want to regenerate the Project Datasource.

As with all Datasources, you will need to supply user access credentials for the NDLFXFile database, which we recommend that you do within the publish profile when publishing your form, rather than through the NDLFXFile Datasource's properties.

  • New Datasource from Form will, by default, use the same instance of SQL Server to store the NDLFXFile database as the Form Datasource. If you have multiple forms with File Upload elements and you specify the same instance of SQL Server for all of these forms, they will all use the same NDLFXFile database and table. You can specify a different instance of SQL Server to be used for the NDLFXFile database within the publish profile, when publishing your form, if you prefer.
  • If you use the same database for multiple forms and you import the NDLFXFile database as an Imported Datasource, you could potentially download file data from all forms using this file to a single form, which may or may not be desirable. Accessing previously uploaded files via a file upload sister table instead, will restrict access to files recorded in that table and won't give access to other form's files.

 

 

By default IIS restricts file uploads to a maximum file size of 4 MB.

 

  • If you allow users to save and restore a form which contains File Upload Elements, the file selections cannot be saved because of restrictions due to browser security. When the form is restored, File Upload Elements placed directly on the form will be empty and display the Choose File button instead of the previously selected file name(s). The user will need to reselect the required files. After restoring the form, the form will display the first page containing any File Upload Element marked as Required.

    File Uploads performed from a Recordset's edit page, however, will still appear to have the data saved in the Recordset after the restore. However, the file names associated with the records displayed in the Recordset will have been lost from the File Upload Elements themselves and the user will need to re-edit each row and reselect the file to be uploaded. On the edit page any File Upload Elements will be empty and will display the Choose File button. If you only have File Upload Elements in Recordset edit pages, the form will not display the first page containing a File Upload Element after a restore.

    If you have any File Upload Elements on your form, a warning message telling you that File Upload Elements are not supported with Save and Restore will be displayed when you publish the form, to remind you.

 

 


See also:

File Download