Your search did not match any results.
FileUploader

Validation

This demo shows how to use the allowedFileExtensions and maxFileSize options to limit the maximum size and specify file extensions that the FileUploader accepts. Note that demonstrated validation is client-side — you should implement the server-side validation. You can see an example under the FileUploaderController tab.

<div class="main-block"> <div class="file-uploader-block"> @(Html.DevExtreme().FileUploader() .Name("imageFile") .Accept("*") .Multiple(true) .AllowedFileExtensions(new List<string> { ".jpg", ".jpeg", ".gif", ".png" }) .UploadMode(FileUploadMode.UseButtons) .UploadUrl(Url.Action("UploadImage", "FileUploader")) ) <span class="note">Allowed file extensions: <span>.jpg, .jpeg, .gif, .png</span>.</span> </div> <div class="file-uploader-block" style="float: right"> @(Html.DevExtreme().FileUploader() .Name("smallFile") .Accept("*") .Multiple(true) .MaxFileSize(4000000) .UploadMode(FileUploadMode.UseButtons) .UploadUrl(Url.Action("UploadSmallFile", "FileUploader")) ) <span class="note">Maximum file size: <span>4 MB.</span></span> </div> </div>
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace DevExtreme.NETCore.Demos.Controllers { public partial class FileUploaderController : Controller { public ActionResult Validation() { return View(); } [HttpPost] public ActionResult UploadImage(IFormFile imageFile) { try { string[] imageExtensions = { ".jpg", ".jpeg", ".gif", ".png" }; var fileName = imageFile.FileName.ToLower(); var isValidExtenstion = imageExtensions.Any(ext => { return fileName.LastIndexOf(ext) > -1; }); if(isValidExtenstion) { // Uncomment to save the file //var path = Path.Combine(_hostingEnvironment.WebRootPath, "uploads"); //if(!Directory.Exists(path)) // Directory.CreateDirectory(path); //using(var fileStream = System.IO.File.Create(Path.Combine(path, file.FileName))) { // file.CopyTo(fileStream); //} } } catch { Response.StatusCode = 400; } return new EmptyResult(); } [HttpPost] public ActionResult UploadSmallFile(IFormFile smallFile) { try { var maxFileSize = 4000000; if(smallFile.Length < maxFileSize) { // Uncomment to save the file //var path = Path.Combine(_hostingEnvironment.WebRootPath, "uploads"); //if(!Directory.Exists(path)) // Directory.CreateDirectory(path); //using(var fileStream = System.IO.File.Create(Path.Combine(path, file.FileName))) { // file.CopyTo(fileStream); //} } } catch { Response.StatusCode = 400; } return new EmptyResult(); } } }
.file-uploader-block { width: 350px; float: left; } .note { font-size: 10pt; color: #484848; margin-left: 9px; } .note > span { font-weight: 700 } .main-block { max-width: 900px; min-width: 700px; }