# Blazor FileSelect Overview

The <a href = "https://www.telerik.com/blazor-ui/fileselect" target="_blank">Telerik UI for Blazor FileSelect component</a> helps users select one or more files from their local file system.

The Blazor FileSelect provides a [Stream](https://docs.microsoft.com/en-us/dotnet/api/system.io.stream?view=net-6.0) for each selected file, so that you can manipulate the file in-memory or save (upload) it to the server file system.

## FileSelect vs. Upload

The FileSelect and Upload components are similar and even inter-changeable. The major difference is how they communicate with the server and how the user files are received. These two aspects can determine which component to use.

* The [FileSelect](https://www.telerik.com/blazor-ui/documentation/components/fileselect/overview) is more suitable for WebAssembly apps if you want to receive and manipulate the file in the browser's .NET runtime. The user files are received in the [FileSelect `OnSelect` event](https://www.telerik.com/blazor-ui/documentation/components/fileselect/events#onselect). Uploading the files to a remote server is optional and depends on manual coding in the `OnSelect` handler. The benefit is that FileSelect allows full control over the upload process. In [Blazor Server](https://www.telerik.com/blazor-ui/documentation/getting-started/web-app) apps, the FileSelect uses the SignalR WebSocket and files over 32 KB require [`MaximumReceiveMessageSize` configuration](https://www.telerik.com/blazor-ui/documentation/components/fileselect/overview#large-file-support).
* The [Upload](https://www.telerik.com/blazor-ui/documentation/components/upload/overview) uses the HTTP protocol. The user files are received by a controller. Prefer the Upload component in [Blazor Server](https://www.telerik.com/blazor-ui/documentation/getting-started/web-app) and WebAssembly apps to directly send files to a remote endpoint, as HTTP is the usual and faster way to do this. Large file support requires [different configurations](https://www.telerik.com/blazor-ui/documentation/components/upload/overview#large-file-uploads), depending on the receiving web server.

## Creating Blazor FileSelect

1. Add the `TelerikFileSelect` tag.
2. Set `AllowedExtensions` to a `List<string>`.
3. Set `MaxFileSize` in bytes.
4. If you are using a [Blazor **Server**](https://www.telerik.com/blazor-ui/documentation/getting-started/web-app) app and `MaxFileSize` is greater than **32 KB**, [increase the maximum SignalR message size](https://www.telerik.com/blazor-ui/documentation/components/fileselect/overview#large-file-support).
5. Implement an [`OnSelect` event handler](https://www.telerik.com/blazor-ui/documentation/components/fileselect/events#onselect).

Steps 2 and 3 are optional, but strongly recommended.

> caption Using the FileSelect

<demo metaUrl="client/fileselect/overview/" height="250"></demo>

## Large File Support

This section applies only to [Blazor **Server**](https://www.telerik.com/blazor-ui/documentation/getting-started/web-app) apps. Blazor **WebAssembly** apps do not require additional configuration for the FileSelect to work with large files.

In [Blazor **Server**](https://www.telerik.com/blazor-ui/documentation/getting-started/web-app) apps, the FileSelect uses the **SignalR WebSocket** to send files from the browser to the server .NET runtime. The default SignalR maximum message size is **32 KB**. To work with larger files, [increase the max WebSocket message size for the Blazor application](https://www.telerik.com/blazor-ui/documentation/knowledge-base/common-increase-signalr-max-message-size).

## Drag-and-Drop File Support

The FileSelect provides built-in file drag-and-drop support, which allows users to drag one or multiple files and drop them anywhere in the component. The [`OnSelect` event](https://www.telerik.com/blazor-ui/documentation/components/fileselect/events#onselect) is raised upon dropping the file. You can handle this event to perform further actions with the selected file.

Additionally, you may define an external drop zone by using the [Telerik UI for Blazor DropZone component](https://www.telerik.com/blazor-ui/documentation/components/dropzone/overview).

## Validation

The FileSelect includes [built-in client-side validation](https://www.telerik.com/blazor-ui/documentation/components/fileselect/validation) for the file size and type (extension). Additional custom validation can take place in the [OnSelect event](https://www.telerik.com/blazor-ui/documentation/components/fileselect/events#onselect).

## Initial Files

The Initial Files feature allows you to display a set of pre-selected files in the FileSelect when the component loads. This functionality is helpful when you want to show files that were previously provided by the user. [Read more about the FileSelect Initial Files feature...](https://www.telerik.com/blazor-ui/documentation/components/fileselect/initial-files)

## Templates

You can use the functionality of the built-in template and modify the appearance of the **Select files...** button. [Read more about the Telerik FileSelect templates...](https://www.telerik.com/blazor-ui/documentation/components/fileselect/templates)

## FileSelect Parameters

The following table lists the FileSelect parameters. Also check the [FileSelect API Reference](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.telerikfileselect) for a full list of properties, methods and events.

<style>
    .article table {
        table-layout: auto;
        word-break: normal;
    }
</style>

| Parameter           | Type and Default Value            | Description                                                                                                                                                                                                                                                                                                      |
| ------------------- | --------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `Accept`            | `string`                          | The [`accept` HTML attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept) of the file `<input>`. It controls what file types and MIME types the browser will allow users to select. Compare with `AllowedExtensions`.                                                                   |
| `AllowedExtensions` | `List<string>`                    | The list of allowed file types. The component will check if the selected files are compliant **after selection**. Compare with `Accept`. Read more at [Validation](https://www.telerik.com/blazor-ui/documentation/components/fileselect/validation).                                                            |
| `Capture`           | `string`                          | The [`capture` HTML attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/capture) of the `<input type="file" />` element. It enables users to provide a file directly from their device camera.                                                                                               |
| `Class`             | `string`                          | Renders a custom CSS class to the `<div class="k-upload">` element. (The FileSelect reuses the Upload HTML rendering.)                                                                                                                                                                                           |
| `DropZoneId`        | `string`                          | The id that is used to connect the FileSelect to an external [DropZone](https://www.telerik.com/blazor-ui/documentation/components/dropzone/overview). Assign a value matching the `Id` of the DropZone you are connecting the component with.                                                                   |
| `Enabled`           | `bool`<br />(`true`)              | Enables file selection.                                                                                                                                                                                                                                                                                          |
| `Id`                | `string`                          | Renders an `id` attribute to the `<input type="file" />` element. Can be used together with a `<label>`.                                                                                                                                                                                                         |
| `MaxFileSize`       | `long?`                           | Sets the maximum allowed file size in bytes. Read more in the [Large File Support](https://www.telerik.com/blazor-ui/documentation/components/fileselect/overview#large-file-support) section and in the [Validation](https://www.telerik.com/blazor-ui/documentation/components/fileselect/validation) article. |
| `MinFileSize`       | `long?`                           | Sets the minimum allowed file size in bytes. Read more in the [Validation](https://www.telerik.com/blazor-ui/documentation/components/fileselect/validation) article.                                                                                                                                            |
| `Multiple`          | `bool`<br />(`true`)              | Sets if the user can select several files at the same time.                                                                                                                                                                                                                                                      |
| `Files`             | `IEnumerable<FileSelectFileInfo>` | Collection of files that will be initially displayed in the FileSelect file list.                                                                                                                                                                                                                                |

## FileSelect Reference and Methods

The File Select exposes methods for programmatic operation. To use them, define a reference to the component instance with the `@ref` attribute. The FileSelect methods are:

| Method                           | Description                                                                                                                                                                                                               |
| -------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `ClearFiles()`                   | Clears all files from the list.                                                                                                                                                                                           |
| `OpenSelectFilesDialog()`        | Shows the browser's file selection dialog. This method [doesn't work in Safari due to browser security restrictions](https://www.telerik.com/blazor-ui/documentation/knowledge-base/upload-openselectfilesdialog-safari). |
| `RemoveFileAsync(string fileId)` | Removes the file with the specified identifier from the collection.                                                                                                                                                       |

For a complete list of all FileSelect methods, see the [FileSelect API reference](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.telerikfileselect#methods).

> caption Get reference to the FileSelect and execute methods

<demo metaUrl="client/fileselect/methods/" height="250"></demo>

## Next Steps

* [Explore FileSelect Validation](https://www.telerik.com/blazor-ui/documentation/components/fileselect/validation)
* [Use FileSelect Events](https://www.telerik.com/blazor-ui/documentation/components/fileselect/events)

## See Also

* [FileSelect API](https://www.telerik.com/blazor-ui/documentation/api/telerik.blazor.components.telerikfileselect)
* [Live Demo: FileSelect](https://demos.telerik.com/blazor-ui/fileselect/overview)
