blazor-devexpress-dot-blazor-dot-fileuploadstarteventargs-48ec217e.md
Specifies a target URL for the upload request.
Namespace : DevExpress.Blazor
Assembly : DevExpress.Blazor.v25.2.dll
NuGet Package : DevExpress.Blazor
public string UploadUrl { get; set; }
| Type | Description |
|---|---|
| String |
The upload URL.
|
Handle the FileUploadStart event to control file upload before it is started. Use the event argument’s FileInfo property to get information about the file (its name, type, size, and so on).
The Upload component’s UploadUrl property specifies a path of a server-side controller’s action that processes all the upload requests. Use the event argument’s UploadUrl property to change the controller action based on conditions. The snippet below changes the upload URL for PNG files.
<DxUpload Name="myFile" UploadUrl="https://localhost:10000/api/Upload/UploadFile/"
FileUploadStart="@OnFileUploadStart">
</DxUpload>
@code {
void OnFileUploadStart(FileUploadStartEventArgs e) {
if (e.FileInfo.Type == "image/png")
e.UploadUrl = "https://localhost:10000/api/Upload/UploadPng/";
}
}
using System.IO;
using System.Linq;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
[Route("api/[controller]")]
public class UploadController : ControllerBase {
private readonly IWebHostEnvironment _hostingEnvironment;
public UploadController(IWebHostEnvironment hostingEnvironment) {
_hostingEnvironment = hostingEnvironment;
}
[HttpPost]
[Route("UploadFile")]
public ActionResult UploadFile(IFormFile myFile) {
// ...
}
[HttpPost]
[Route("UploadPng")]
public ActionResult UploadPng(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();
}
}
See Also
FileUploadStartEventArgs Class