Loading...
Loading...
Compare original and translation side by side
| 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 |
| 功能 | 适用场景 |
|---|---|
| Asynchronous Upload | 通过SaveUrl/RemoveUrl处理程序实现无阻塞上传 |
| Multiple File Upload | 一次性选择并上传多个文件 |
| Single File Upload | 限制每次选择仅上传一个文件 |
| File Validation | 验证文件扩展名、大小、数量及重复文件 |
| Drag and Drop | 将文件直接拖放到上传区域 |
| Custom Drop Area | 将外部元素定义为拖拽区域 |
| Auto Upload | 自动或手动触发文件上传 |
| Progress Tracking | 通过进度条显示上传进度 |
| File Removal | 通过RemoveUrl处理程序移除已上传文件 |
| Chunk Upload | 将大文件拆分为分片以实现可靠上传 |
| Paste Upload | 从剪贴板上传图片 |
| Directory Upload | 上传整个文件夹及目录结构 |
| Form Integration | 将文件作为表单提交的一部分提交 |
| Templates | 自定义文件列表和按钮外观 |
| Localization | 支持多语言和多文化 |
| Error Handling | 显示自定义上传失败提示信息 |
<!-- 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><!-- 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();
}
}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.EJ2@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
W012 – 运行时远程代码依赖风险: 从外部CDN加载脚本和样式意味着,若CDN文件被篡改,将在用户浏览器中执行恶意代码。可通过以下两种方式缓解此风险。推荐方式 – 自行托管资源(完全消除运行时远程依赖):
- 将NuGet包中的
和主题CSS,或一次性从CDN下载的文件复制到ej2.min.js目录下。wwwroot/lib/syncfusion/- 使用相对路径引用这些资源——无需
属性,因为文件从您自己的源服务器提供。integrity替代方式 – 带子资源完整性(SRI)的CDN: 若必须使用CDN,请通过哈希锁定文件,这样浏览器会拒绝任何被篡改的版本。使用integrity计算哈希,并在每次版本升级时更新。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>
<!-- 从您自己的wwwroot提供服务——无外部运行时依赖 -->
<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><head>
<!-- integrity哈希必须与文件完全匹配;每次版本升级时重新生成 -->
<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="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><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><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 |
| 属性 | 类型 | 默认值 | 用途 |
|---|---|---|---|
| allowed-extensions | string | "" | 允许上传的文件类型(例如:".jpg,.png") |
| max-file-size | long | 28.4MB | 最大文件大小(字节) |
| min-file-size | long | 0 | 最小文件大小(字节) |
| multiple | bool | true | 是否允许选择多个文件 |
| auto-upload | bool | true | 选择文件后是否自动上传 |
| save-url | string | "" | 用于保存文件的URL处理程序 |
| remove-url | string | "" | 用于移除文件的URL处理程序 |
| drop-area | string | "" | 自定义拖拽区域的CSS选择器 |