DxFileInput.AcceptedFileTypes Property
Specifies MIME types users can add to the file list.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v24.1.dll
NuGet Package: DevExpress.Blazor
Declaration
[Parameter]
public List<string> AcceptedFileTypes { get; set; }
Property Value
Type | Description |
---|---|
List<String> | A list of allowed MIME file types. |
Remarks
Once a user selects files in the Open dialog or drags files onto a drop zone, the File Input component adds these files to the file list. In Instant
upload mode (default), the component starts to upload a file once it appears in the file list. In OnClick
upload mode, the File Input starts to upload a file once a user clicks an upload button.
Specify the following properties to limit the list of file types that the File Input component can upload:
AcceptedFileTypes
Specifies MIME types of files that users can add to the file list. The component passes this property value to the accept attribute of the underlying
input
HTML element. The element applies the corresponding filter to the Open dialog.- AllowedFileExtensions
Specifies extensions of files that the File Input component allows users to upload. Once a user adds a file to the file list, the component validates the file name extension. If validation fails, the File Input cannot upload this file and displays an error message.
The AcceptedFileTypes
property accepts a list of the following strings:
- File types (
"image/*"
and"video/*"
, for instance) - File extensions (
"image/png"
and"video/mp4"
, for instance)
The following example allows users to upload any images and PDF files:
<DxFileInput FilesUploading="OnFilesUploading"
AcceptedFileTypes="@(new List<string> { "image/*", "application/pdf"})" />
@code {
async Task OnFilesUploading(FilesUploadingEventArgs args) {
foreach (var file in args.Files) {
/* The following code is intended for demonstration purposes only.
Do not read a stream directly in memory to avoid performance and security-related issues. */
using var stream = new System.IO.MemoryStream();
await file.OpenReadStream(file.Size).CopyToAsync(stream);
}
}
}