The File field allows adding files to your content. You can use it to add files from anywhere in your repository and even restrict it to a specific folder.
Editing UI Widget
This field is displayed as a button labelled with the field’s label
, which opens a file picker when clicked. Once a file was selected, its path will be visible along with an option to remove the file if the removable
option is set to true
.
Output Format
The File field outputs the path of the file in the current project as a string.
Options
The following options are available for this field (default values shown):
{
"removable": false,
"allowUpload": false,
"root": null,
"filetypes": ["pdf", "zip"]
}
removable: whether or not the file may be removed after being set, resetting the field’s value to
null
allowUpload: whether or not a new file may be uploaded using this file picker
root: the root folder from which to pick files, defaults to the root of the project, but may be any folder within it
filetypes: an array of file extensions without a leading dot that may be added to this field. For performance reasons, be aware that this only compares the extension of the file name!
Validation
The following validation options are available for this field (default values shown):
{
"max": null,
"required": false,
"unit": "filesize (MB)"
}
Notes
If you are looking for a way to add an image to your content instead, the Image field is what you are looking for.
If the max
value of the validation options is not set, the global maximum file size set in the media library options will be used instead, if set.
Setting the root
option to the same directory as your Media Library will allow you and your collaborators to upload new files to the project by adding them to the Media Library without having to set allowUploads
to true
for the field itself. This will give you greater control about what role may do what via the Media Library Permissions.
Additionally, since version 0.6.0
of Mattrbld, it is also possible to add Media Collections, which allow for even more control and linking uploaded files via link-fields. You can learn more about them in the article about Media Collections.
Version History
Version 2: added a new option to enable / disable uploads through the file picker. Defaults to
false
. If you don’t upgrade your fields, your users will no longer be able to upload files straight from the file pickerVersion at launch: 1