How to check file size before upload in ASP.NET Core File Upload
24 Aug 20262 minutes to read
By Using the uploading event, you can get the file size before uploading to the server. The file object contains the file size in bytes only. You can convert the size to standard formats (KB or MB) using the bytesToSize method.
@{
var asyncSettings = new Syncfusion.EJ2.Inputs.UploaderAsyncSettings { SaveUrl = "https://services.syncfusion.com/aspnet/production/api/FileUploader/Save", RemoveUrl = "https://services.syncfusion.com/aspnet/production/api/FileUploader/Remove" };
}
<div class="col-lg-8 control-section">
<div class="control_wrapper">
<ejs-uploader id="UploadFiles" asyncSettings="@asyncSettings" autoUpload="false" uploading="onBeforeUpload">
</ejs-uploader>
</div>
</div>
<script>
function onBeforeUpload(args) {
var uploadObj = document.getElementById("UploadFiles").ej2_instances[0];
// get the file size in bytes
var sizeInBytes = args.fileData.size;
// get the file size in standard format
alert("File size is: " + uploadObj.bytesToSize(sizeInBytes))
}
</script>.control_wrapper {
max-width: 500px;
margin: auto;
}
.control_wrapper .e-upload .e-upload-drag-hover {
margin: 0;
}Explore the ASP.NET Core File Upload feature tour page to discover its groundbreaking features. You can also check out our ASP.NET Core File Upload example to see how to browse and select files for upload to the server.