InputFile
The FluentInputFile
wraps the native Blazor InputFile
component and extends it with drag/drop zone support. See the examples below for some different ways on how to use this component.
Customization: You can localize this component by customizing the content of ChildContent
, but also the content of the progress area via the ProgressTemplate
attribute.
The default progress area displays Loading, Completed or Canceled labels via static variables FluentInputFile.ResourceLoadingXXX
.
These can be accessed to globally adapt the default display if you wish.
note: This component is not yet fully compatible with accessibility.
Examples
Default
By default this component will use the SaveToTemporaryFolder
mode which creates a local file.
Maximum of 4 files allowed.
Manual upload
Manual upload with loading indicator
Mode = InputFileMode.Buffer
Using the Buffer
mode will load the entire file into memory during uploading.
This mode is recommended when you cannot store local files and you are working with small files and have enough memory available.
Mode = InputFileMode.Stream
The Stream
mode gives you more control of the uploading process to save memory. In order for it to work you will need to implement the handling for the stream on your own.
This mode is recommended when you want to upload large files which you do not want to hold entirely in memory.
Disabled Component
Documentation
FluentInputFile Class
Parameters
Name | Type | Default | Description |
---|---|---|---|
Accept | string | Gets or sets the filter for what file types the user can pick from the file input dialog box. Example: '.gif, .jpg, .png, .doc', 'audio/*', 'video/*', 'image/*' See https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/accept for more information. | |
AnchorId | string | Gets or sets the identifier of the source component clickable by the end user. | |
BufferSize | uint | 10240 | Gets or sets the sze of buffer to read bytes from uploaded file (in bytes). Default value is 10 KiB. |
ChildContent | RenderFragment? | Gets or sets the child content of the component. | |
Disabled | bool | False | Disables the form control, ensuring it doesn't participate in form submission. |
DragDropZoneVisible | bool | True | Gets or sets a value indicating whether the Drag/Drop zone is visible. Default is true. |
MaximumFileCount | int | 10 | To select multiple files, set the maximum number of files allowed to be uploaded. Default value is 10. |
MaximumFileSize | long | 10485760 | Gets or sets the maximum size of a file to be uploaded (in bytes). Default value is 10 MiB. |
Mode | InputFileMode | SaveToTemporaryFolder | Gets or sets the type of file reading. For SaveToTemporaryFolder, use FluentInputFileEventArgs.LocalFile to retrieve the file.For Buffer, use FluentInputFileEventArgs.Buffer to retrieve bytes.For Stream, use FluentInputFileEventArgs.Stream to have full control over retrieving the file. |
Multiple | bool | False | To enable multiple file selection and upload, set the Multiple property to true. Set FluentInputFile.MaximumFileCount to change the number of allowed files. |
ProgressPercent | int | 0 | Gets or sets the current global value of the percentage of a current upload. |
ProgressTemplate | RenderFragment<ProgressFileDetails>? | Gets or sets the progress content of the component. | |
ProgressTitle | string | Gets the current label display when an upload is in progress. |
EventCallbacks
Name | Type | Description |
---|---|---|
OnCompleted | EventCallback<IEnumerable<FluentInputFileEventArgs>> | Raise when all files are completely uploaded. |
OnFileCountExceeded | EventCallback<int> | Raised when the FluentInputFile.MaximumFileCount is exceeded.The return parameter specifies the total number of files that were attempted for upload. |
OnFileError | EventCallback<FluentInputFileEventArgs> | Raise when a file raised an error. Not yet used. |
OnFileUploaded | EventCallback<FluentInputFileEventArgs> | Raise when a file is completely uploaded. |
OnInputFileChange | EventCallback<InputFileChangeEventArgs> | Use the native event raised by the If you use this event, the FluentInputFile.OnFileUploaded will never be raised. |
OnProgressChange | EventCallback<FluentInputFileEventArgs> | Raise when a progression step is updated. You can use FluentInputFile.ProgressPercent and FluentInputFile.ProgressTitle to have more detail on the progression. |
ProgressPercentChanged | EventCallback<int> | Gets or sets a callback that updates the FluentInputFile.ProgressPercent . |
Methods
Name | Parameters | Type | Description |
---|---|---|---|
DisposeAsync | ValueTask | ||
ShowFilesDialogAsync | Task | Open the dialog-box to select files. Use FluentInputFile.AnchorId instead to specify the ID of the button (for example) on which the user should click.⚠️ This method doesn't work on Safari and iOS. |
Known Issues
Starting with .NET 6, the InputFile
component does not work in Server-Side Blazor applications using Autofac IoC containers. This issue is being tracked here: aspnetcore#38842
Enable HubOptions DisableImplicitFromServicesParameters in program/startup to workaround this issue.
builder.Services
.AddServerSideBlazor()
.AddHubOptions(opt =>
{
opt.DisableImplicitFromServicesParameters = true;
});