blazor-devexpress-dot-blazor-dot-dxupload-17d75a09.md
Specifies file extensions that the Upload component can upload.
Namespace : DevExpress.Blazor
Assembly : DevExpress.Blazor.v25.2.dll
NuGet Package : DevExpress.Blazor
[Parameter]
public List<string> AllowedFileExtensions { get; set; }
| Type | Description |
|---|---|
| List<String> |
A list of allowed file extensions.
|
You can use the following APIs to specify file types and extensions accepted by Upload.
The AcceptedFileTypes property sets the file type filter in the Open File dialog. The property value is passed to the accept attribute of the underlying input HTML element.
If a user removes the filter, the Open File dialog displays all file types and users can select files that do not match AcceptedFileTypes.
A user can also skip the Open File dialog and simply drop files onto the drop zone.
Once a file is added to the file list, the component validates the following:
false.AllowedFileExtensions.If validation fails, the Upload cannot upload the file and displays an error message.
<DxUpload Name="myFile" UploadUrl="https://localhost:10000/api/Upload/Upload/"
AllowedFileExtensions="@(new List<string> { ".jpg", ".jpeg", ".gif", ".png" })">
</DxUpload>
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
namespace BlazorDemo.AspNetCoreHost;
[Route("api/[controller]")]
[ApiController]
public class UploadController : ControllerBase {
[HttpPost("[action]")]
public ActionResult Upload(IFormFile myFile) {
try {
// Write code that saves the 'myFile' file.
// Don't rely on or trust the FileName property without validation.
} catch {
return BadRequest();
}
return Ok();
}
}
Once a user selected or dropped a file, the Upload validates the file’s extension on the client. If the extension is not allowed, the Upload displays an error.
For additional information on server-side validation, refer to Server-Side Validation.
See Also