File upload

A FileUploadFormElement writes an <input> element type="file" to the output. This formElement can be used to select one or multiple files form the users device storage.

Element and builder

The ViewElement implementation is FileUploadFormElement and has an equivalent FileUploadFormElementBuilder. A builder can be created using BootstrapViewElements.bootstrap.builders.file() factory methods.

FileUploadFormElement attributes

Attribute Description Default

accept

A string that defines the file types the file input should accept. This string is a comma-separated list of unique type specifiers. For example "images/*"

Accept attribute is not set so All fileTypes are allowed by default

multiple

A boolean indicting if multiple files are allowed.

Multiple attribute is not set so multiple files are not allowed by default

Examples

Creating a basic FileUploadFormElement

import static com.foreach.across.modules.bootstrapui.ui.factories.BootstrapViewElements.bootstrap;

bootstrap.builders.file()
        .controlName( "singleFile" )
        .build();

Handle multiFile upload

An input file type can be configured so multiple files can be uploaded at once.

Given the following builder configuration

import static com.foreach.across.modules.bootstrapui.ui.factories.BootstrapViewElements.bootstrap;

bootstrap.builders.file()
      .controlName( "multiFIle" )
      .multiple( true )
      .build();

Change what files to accept

By providing the accept parameter the file upload is limited to those file types.

Given the following builder configuration

import static com.foreach.across.modules.bootstrapui.ui.factories.BootstrapViewElements.bootstrap;

bootstrap.builders.file()
      .controlName( "pdfFile" )
      .accept( ".pdf" )
      .build();