Loading...
Loading...
Complete guide to implementing the Syncfusion Uploader component in ASP.NET Core applications. Use this when working with file uploads, asynchronous processing, validation, drag-and-drop support, or enterprise-grade file handling for professional web forms.
npx skill4agent add syncfusion/aspnetcore-ui-components-skills syncfusion-aspnetcore-uploader| Feature | Use Case |
|---|---|
| Asynchronous Upload | Non-blocking uploads with SaveUrl/RemoveUrl handlers |
| Multiple File Upload | Select and upload many files at once |
| Single File Upload | Restrict to one file per selection |
| File Validation | Validate extensions, size, count, duplicates |
| Drag and Drop | Drop files directly onto uploader area |
| Custom Drop Area | Define external elements as drop zones |
| Auto Upload | Upload files automatically or manually |
| Progress Tracking | Display upload progress with progress bar |
| File Removal | Remove uploaded files with RemoveUrl handler |
| Chunk Upload | Break large files into chunks for reliable upload |
| Paste Upload | Upload images from clipboard |
| Directory Upload | Upload entire folders and directory structure |
| Form Integration | Submit files as part of form submission |
| Templates | Customize file list and button appearance |
| Localization | Support multiple languages and cultures |
| Error Handling | Display upload failures with custom messages |
<!-- Views/Home/Index.cshtml -->
<div class="form-group">
<ejs-uploader id="uploader">
<e-async-settings save-url="Home/Save" remove-url="Home/Remove"></e-async-settings>
<e-upload-files></e-upload-files>
</ejs-uploader>
</div>
<div id="uploadedFiles"></div>using Microsoft.AspNetCore.Mvc;
using System.IO;
public class HomeController : Controller
{
private readonly IWebHostEnvironment _webHostEnvironment;
public HomeController(IWebHostEnvironment webHostEnvironment)
{
_webHostEnvironment = webHostEnvironment;
}
[HttpPost]
public IActionResult Save(IFormFile[] uploader)
{
if (uploader != null && uploader.Length > 0)
{
string uploadPath = Path.Combine(_webHostEnvironment.WebRootPath, "Uploads");
if (!Directory.Exists(uploadPath))
Directory.CreateDirectory(uploadPath);
foreach (IFormFile file in uploader)
{
string filePath = Path.Combine(uploadPath, file.FileName);
using (FileStream fs = System.IO.File.Create(filePath))
{
file.CopyTo(fs);
fs.Flush();
}
}
}
return Ok();
}
[HttpPost]
public IActionResult Remove(string[] files)
{
string uploadPath = Path.Combine(_webHostEnvironment.WebRootPath, "Uploads");
foreach (string file in files)
{
string filePath = Path.Combine(uploadPath, file);
if (System.IO.File.Exists(filePath))
System.IO.File.Delete(filePath);
}
return Ok();
}
}@addTagHelper *, Syncfusion.EJ2W012 – Runtime remote-code dependency risk: Loading scripts and styles from an external CDN means a compromised or tampered CDN file would execute in your users' browsers. Mitigate this with one of the two approaches below.Preferred – Self-host the assets (eliminates the runtime remote dependency entirely):
- Copy
and the theme CSS from the NuGet package or a one-time CDN download intoej2.min.js.wwwroot/lib/syncfusion/- Reference them with relative paths — no
attribute needed because the files are served from your own origin.integrityAlternative – CDN with Subresource Integrity (SRI): If you must use the CDN, pin the file with anhash so the browser rejects any tampered version. Compute the hash withintegrityand update it on every version upgrade.openssl dgst -sha384 -binary <file> | openssl base64 -A
<head>
<!-- Served from your own wwwroot — no external runtime dependency -->
<link rel="stylesheet" href="~/lib/syncfusion/fluent.css" />
</head>
<body>
@RenderBody()
<script src="~/lib/syncfusion/ej2.min.js"></script>
<ejs-scripts></ejs-scripts>
</body><head>
<!-- integrity hash must match the exact file; regenerate on every version upgrade -->
<link rel="stylesheet"
href="https://cdn.syncfusion.com/ej2/24.1.48/fluent.css"
integrity="sha384-REPLACE_WITH_ACTUAL_HASH_FOR_fluent.css"
crossorigin="anonymous" />
</head>
<body>
@RenderBody()
<script src="https://cdn.syncfusion.com/ej2/24.1.48/dist/ej2.min.js"
integrity="sha384-REPLACE_WITH_ACTUAL_HASH_FOR_ej2.min.js"
crossorigin="anonymous"></script>
<ejs-scripts></ejs-scripts>
</body><ejs-uploader id="multiUploader"
allowed-extensions=".jpg,.png,.pdf,.doc,.docx"
max-file-size="5242880"
auto-upload="false"
multiple="true"
uploading="onUploading"
success="onSuccess"
failure="onFailure">
<e-async-settings save-url="Home/Save" remove-url="Home/Remove"></e-async-settings>
</ejs-uploader>
<script>
function onUploading(args) {
console.log('Uploading: ' + args.file.name);
console.log('Progress: ' + (args.percentComplete * 100) + '%');
}
function onSuccess(args) {
if (args.operation === 'upload') {
console.log(args.file.name + ' uploaded successfully');
}
}
function onFailure(args) {
console.log('Upload failed: ' + args.response);
}
</script><ejs-uploader id="singleUploader"
allowed-extensions=".jpg,.png,.jpeg"
max-file-size="2097152"
multiple="false"
selected="onFileSelected"
auto-upload="true">
<e-async-settings save-url="Home/Save" remove-url="Home/Remove"></e-async-settings>
</ejs-uploader>
<script>
function onFileSelected(args) {
if (args.filesData.length > 1) {
args.filesData.splice(1);
alert('Only one file can be selected');
}
}
</script><div id="dropArea" style="border: 2px dashed #ccc; padding: 20px; min-height: 200px;">
Drop files here
</div>
<ejs-uploader id="uploader"
drop-area="#dropArea"
auto-upload="true">
<e-async-settings save-url="Home/Save" remove-url="Home/Remove"></e-async-settings>
</ejs-uploader>| Property | Type | Default | Purpose |
|---|---|---|---|
| allowed-extensions | string | "" | File types to allow (e.g., ".jpg,.png") |
| max-file-size | long | 28.4MB | Maximum file size in bytes |
| min-file-size | long | 0 | Minimum file size in bytes |
| multiple | bool | true | Allow multiple file selection |
| auto-upload | bool | true | Upload files automatically after selection |
| save-url | string | "" | URL handler for saving files |
| remove-url | string | "" | URL handler for removing files |
| drop-area | string | "" | CSS selector for custom drop area |