# SiFileUploadDirective documentation

**Kind:** directive

**Selector:** `input[type="file"][siFileUpload]`

```
import { SiFileUploadDirective } from '@siemens/element-ng/file-uploader';
```

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

Example:

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

```
directive SiFileUploadDirective
```

#### Input Properties

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| [accept](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-upload.directive.ts#L79-L79>) | `string \| undefined` |  | Define which file types are suggested in file browser.<br><br>See: [https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file\#attr-accept](<https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#attr-accept>) |
| [directoryUpload](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-upload.directive.ts#L99-L99>) | `boolean` | `false` | Enable directory upload. |
| [errorTextFileMaxSize](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-upload.directive.ts#L71-L73>) | `TranslatableString` | `` $localize`:@@SI_FILE_UPLOADER.ERROR_FILE_SIZE_EXCEEDED:Max. {{maxFileSize}}` `` | Message or translation key if file exceeds the maximum file size limit. |
| [errorTextFileType](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-upload.directive.ts#L59-L61>) | `TranslatableString` | `` $localize`:@@SI_FILE_UPLOADER.ERROR_FILE_TYPE:Invalid file type` `` | Text or translation key of message title if incorrect file type is dragged / dropped. |
| [maxFileSize](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-upload.directive.ts#L84-L84>) | `number \| undefined` |  | Define maximal allowed file size in bytes. |
| [multiple](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-upload.directive.ts#L92-L92>) | `boolean` | `false` | Defines whether the file input allows selecting multiple files. When [directoryUpload](<index.html#SiFileUploadDirective.directoryUpload>) is enabled, this will have no effect. |

#### Output Properties

| Name | Type | Description |
| --- | --- | --- |
| [fileError](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-upload.directive.ts#L116-L116>) | `FileUploadError` | Event emitted when file validation errors occur, including files that were ignored due to size or type. |
| [filesAdded](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-upload.directive.ts#L111-L111>) | `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](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-upload.directive.ts#L105-L105>) | `UploadFile[]` | Event emitted when valid files are added. Invalid files (due to size or type) will be ignored and instead the [fileError](<index.html#SiFileUploadDirective.fileError>) event will be emitted. |

#### Attributes and Methods

##### fileSizeToString

[Source for fileSizeToString](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-upload.directive.ts#L285-L287>)

```
fileSizeToString(num: number): string
```

#### Parameters

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| [num](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-upload.directive.ts#L285-L285>) | `number` |  |  |

**Returns:** [string](<https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String>)

##### formatFileSize

[Source for formatFileSize](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-upload.directive.ts#L289-L303>)

**Modifiers:** static

```
formatFileSize(num: number, formatter?: Intl.NumberFormat): string
```

#### Parameters

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| [num](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-upload.directive.ts#L289-L289>) | `number` |  |  |
| [formatter](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-upload.directive.ts#L289-L289>) (optional) | `Intl.NumberFormat` |  |  |

**Returns:** [string](<https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String>)

##### handleFiles

[Source for handleFiles](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-upload.directive.ts#L130-L161>)

Handle files from input or drag and drop

```
handleFiles(files: FileList | null): void
```

#### Parameters

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| [files](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-upload.directive.ts#L130-L130>) | `FileList \| null` |  |  |

**Returns:** [void](<https://www.typescriptlang.org/docs/handbook/2/functions.html#void>)

##### handleItems

[Source for handleItems](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-upload.directive.ts#L166-L221>)

Handle directory entries for drag and drop

```
handleItems(items: DataTransferItemList): void
```

#### Parameters

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| [items](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-upload.directive.ts#L166-L166>) | `DataTransferItemList` |  |  |

**Returns:** [void](<https://www.typescriptlang.org/docs/handbook/2/functions.html#void>)

##### reset

[Source for reset](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-upload.directive.ts#L226-L228>)

Reset the file input value

```
reset(): void
```

**Returns:** [void](<https://www.typescriptlang.org/docs/handbook/2/functions.html#void>)

##### triggerClick

[Source for triggerClick](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-upload.directive.ts#L233-L235>)

Trigger the file input click

```
triggerClick(): void
```

**Returns:** [void](<https://www.typescriptlang.org/docs/handbook/2/functions.html#void>)

### Types Documentation

### [TranslatableString](<https://github.com/siemens/element/blob/main/projects/element-translate-ng/translate-types/global.types.ts#L18-L18>)

**Kind:** type alias

```
import type { TranslatableString } from '@siemens/element-translate-ng/translate-types';
```

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.

```
type TranslatableString = string & Translatable
```

### [FileUploadError](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-upload.directive.ts#L18-L21>)

**Kind:** interface

```
import type { FileUploadError } from '@siemens/element-ng/file-uploader';
```

```
interface FileUploadError extends UploadFile
```

#### Properties

| Name | Type | Description |
| --- | --- | --- |
| [errorParams](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-uploader.model.ts#L15-L15>) (optional, inherited) | `Record<string, unknown>` | Inherited from [UploadFile](<index.html#t:UploadFile>) |
| [errorText](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-upload.directive.ts#L20-L20>) | `TranslatableString` | Inherited from [UploadFile](<index.html#t:UploadFile>) |
| [file](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-uploader.model.ts#L11-L11>) (inherited) | `File` | Inherited from [UploadFile](<index.html#t:UploadFile>) |
| [fileName](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-uploader.model.ts#L12-L12>) (inherited) | `string` | Inherited from [UploadFile](<index.html#t:UploadFile>) |
| [progress](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-uploader.model.ts#L16-L16>) (inherited) | `number` | Inherited from [UploadFile](<index.html#t:UploadFile>) |
| [size](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-uploader.model.ts#L13-L13>) (inherited) | `string` | Inherited from [UploadFile](<index.html#t:UploadFile>) |
| [status](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-upload.directive.ts#L19-L19>) | `"invalid"` | Inherited from [UploadFile](<index.html#t:UploadFile>) |

### [UploadFile](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-uploader.model.ts#L9-L17>)

**Kind:** interface

```
import type { UploadFile } from '@siemens/element-ng/file-uploader';
```

```
interface UploadFile
```

#### Properties

| Name | Type | Description |
| --- | --- | --- |
| [errorParams](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-uploader.model.ts#L15-L15>) (optional) | `Record<string, unknown>` |  |
| [errorText](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-uploader.model.ts#L14-L14>) (optional) | `TranslatableString` |  |
| [file](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-uploader.model.ts#L11-L11>) | `File` |  |
| [fileName](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-uploader.model.ts#L12-L12>) | `string` |  |
| [progress](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-uploader.model.ts#L16-L16>) | `number` |  |
| [size](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-uploader.model.ts#L13-L13>) | `string` |  |
| [status](<https://github.com/siemens/element/blob/main/projects/element-ng/file-uploader/si-file-uploader.model.ts#L10-L10>) | `"error" \| "success" \| "added" \| "invalid" \| "queued" \| "uploading"` |  |
