Upload files
For a more technical API reference, please see the following pages:
FileField - upload a file
The FileField
lets the user upload a single file. Explicit permission for certain file types can optionally be set
using the file_types
argument. The max size in bytes of the file to be uploaded can be set with max_size
.
import viktor as vkt
class Parametrization(vkt.Parametrization):
file = vkt.FileField('Upload a file')
The user input can be obtained through the params argument and can have the following values:
FileResource
object: when a file is selected (see uploading files for an example of usage)None
: when empty
Expand to see all available arguments
In alphabetical order:
-
description: add a tooltip with additional information
file = vkt.FileField('Upload a file', description="This field represents the ...")
-
file_types: optional restriction of file type(s) (case-insensitive)
file = vkt.FileField('Upload a file', file_types=[".png", ".jpg", ".jpeg"])
-
flex: the width of the field between 0 and 100 (default=33)
file = vkt.FileField('Upload a file', flex=50)
-
max_size: optional restriction on file size in bytes (e.g. 10_000_000 = 10 MB)
file = vkt.FileField('Upload a file', max_size=10_000_000)
-
name: defines the position of the parameter in the params
file = vkt.FileField('Upload a file', name="f") # obtained using params.f
-
visible: can be used when the visibility depends on other input fields
file = vkt.FileField('Upload a file', visible=vkt.Lookup("another_field"))
See 'Hide a field' for elaborate examples.
Upload multiple files
If multiple files need to be uploaded at the same time, the MultiFileField
can be used.
import viktor as vkt
class Parametrization(vkt.Parametrization):
files = vkt.MultiFileField('Upload Multiple Files')
The user input can be obtained through the params argument and can have the following values:
- list of
FileResource
objects: when a file is selected (see uploading files for an example of usage) - empty list when empty
Expand to see all available arguments
In alphabetical order:
-
description: add a tooltip with additional information
files = vkt.MultiFileField('Upload Multiple Files', description="This field represents the ...")
-
file_types: optional restriction of file type(s) (case-insensitive)
files = vkt.MultiFileField('Upload Multiple Files', file_types=[".png", ".jpg", ".jpeg"])
-
flex: the width of the field between 0 and 100 (default=33)
files = vkt.MultiFileField('Upload Multiple Files', flex=50)
-
max_size: optional restriction on file size in bytes (e.g. 10_000_000 = 10 MB)
files = vkt.MultiFileField('Upload Multiple Files', max_size=10_000_000)
-
name: defines the position of the parameter in the params
files = vkt.MultiFileField('Upload Multiple Files', name="f") # obtained using params.f
-
visible: can be used when the visibility depends on other input fields
files = vkt.MultiFileField('Upload Multiple Files', visible=vkt.Lookup("another_field"))
See 'Hide a field' for elaborate examples.