Skip to content

SiFileUploadDirective documentation

selector
input[type="file"][siFileUpload]

Directive for handling file uploads with validation for file type and size.

Example:

<input
  #fileInput
  type="file"
  class="d-none"
  siFileUpload
  [accept]="accept()"
  [maxFileSize]="maxFileSize()"
  [multiple]="true"
  (validFiles)="onFilesAdded($event)"
  (fileError)="onFileError($event)"
/>

Input Properties

NameTypeDefaultDescription
accept
stringDefine which file types are suggested in file browser.
See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#attr-accept
directoryUpload
booleanfalseEnable directory upload.
errorTextFileMaxSize
TranslatableString$localize`:@@SI_FILE_UPLOADER.ERROR_FILE_SIZE_EXCEEDED:File exceeds allowed maximum size`Message or translation key if file exceeds the maximum file size limit.
errorTextFileType
TranslatableString$localize`:@@SI_FILE_UPLOADER.ERROR_FILE_TYPE:Incorrect file type selected`Text or translation key of message title if incorrect file type is dragged / dropped.
maxFileSize
numberDefine maximal allowed file size in bytes.
multiple
booleanfalseDefines whether the file input allows selecting multiple files. When directoryUpload is enabled, this will have no effect.

Output Properties

NameTypeDescription
fileError
FileUploadErrorEvent emitted when file validation errors occur, including files that were ignored due to size or type.
filesAdded
UploadFile[]Event emitted when valid files are added. Also includes invalid files, but with status 'invalid' and an errorText describing why they were ignored.
validFiles
UploadFile[]Event emitted when valid files are added. Invalid files (due to size or type) will be ignored and instead the fileError event will be emitted.

Attributes and Methods

NameTypeDefaultDescription
fileSizeToString(...)
(num: number) => stringParameters
formatFileSize(...)
(num: number, formatter: NumberFormat) => stringParameters
handleFiles(...)
(files: (null | FileList)) => voidHandle files from input or drag and drop

Parameters
handleItems(...)
(items: DataTransferItemList) => voidHandle directory entries for drag and drop

Parameters
reset()
() => voidReset the file input value
triggerClick()
() => voidTrigger the file input click

Types Documentation

Represents a translatable string. This can either be a translation key, e.g. ACTIONS.EDIT that will be automatically translated when displayed on the UI or a pre-translated string, e.g. Edit . Equivalent to a normal string in usage and functionality.
Properties
errorText: TranslatableString
file: File from file
fileName: string from fileName
progress: number from progress
size: string from size
status: "invalid"
Properties
errorText?: TranslatableString
file: File
fileName: string
progress: number
size: string
status: ("error" | "invalid" | "success" | "added" | "queued" | "uploading")
Translatable
import

Except where otherwise noted, content on this site is licensed under MIT License.