Back to Devexpress

DxUpload.MaxFileSize Property

blazor-devexpress-dot-blazor-dot-dxupload-cbc24b12.md

latest2.6 KB
Original Source

DxUpload.MaxFileSize Property

Specifies the maximum file size in bytes.

Namespace : DevExpress.Blazor

Assembly : DevExpress.Blazor.v25.2.dll

NuGet Package : DevExpress.Blazor

Declaration

csharp
[Parameter]
public int MaxFileSize { get; set; }

Property Value

TypeDescription
Int32

An integer value that specifies the maximum file size in bytes.

|

Remarks

Use the MaxFileSize and MinFileSize properties to limit an uploaded file’s size. The Upload component validates the file size on the client side and displays an error message if validation fails.

razor
<DxUpload Name="myFile" 
          UploadUrl="https://localhost:10000/api/Upload/Upload/"
          MaxFileSize="4000000"
          MinFileSize="400">
</DxUpload>
csharp
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();
    }
}

You can also use the following Upload properties to validate uploaded files on the client:

  • AcceptedFileTypes - Specifies a file type (MIME type) or multiple types (separated by a comma) that the Upload component accepts.
  • AllowedFileExtensions - Specifies file extensions (an array) that the Upload component accepts.

For additional information on the server-side validation, refer to Server-Side Validation.

Run Demo: Upload - Validation

See Also

DxUpload Class

DxUpload Members

DevExpress.Blazor Namespace