blazor-devexpress-dot-blazor-dot-dxupload-1125e54c.md
Specifies a target URL for the upload request.
Namespace : DevExpress.Blazor
Assembly : DevExpress.Blazor.v25.2.dll
NuGet Package : DevExpress.Blazor
[Parameter]
public string UploadUrl { get; set; }
| Type | Description |
|---|---|
| String |
A string value that specifies a target URL.
|
Set the UploadUrl property to a path of a server-side controller’s action that processes upload requests. You should also specify the Name property to associate the Upload component with the server.
<DxUpload Name="myFile"
UploadUrl="https://localhost:10000/api/Upload/Upload/">
</DxUpload>
Create a controller action that accepts the uploaded file, checks it, and saves it to the target location on a server. Follow the steps below to implement a controller action:
MapControllers method call. Refer to the following topic for additional information: Attribute routing for REST APIs.Use one of the following variants to access the uploaded file:
Create an action with a parameter whose name matches the Name property value.
Use the Name property value to get the uploaded file from form variables.
The following example implements the upload controller:
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();
}
}
To maintain the highest possible security posture, we do not include the full implementation of the Upload controller. To incorporate secure file upload operations in your web app, we recommend that you add different validation types to upload controller code as described in the following help section: Validation. For information on controller implementation code for different file upload scenarios, refer to the following Microsoft article: File Upload Scenarios.
See Also