Get the total size of selected files

21 Dec 20221 minute to read

You can get the total size of selected files before uploading it to the designated server. This can be achieved by using the selected event. Refer to the following example to calculate the total file size.

@{
    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="control_wrapper">
    <ejs-uploader id="UploadFiles" selected="onSelect" asyncSettings="@asyncSettings">
    </ejs-uploader>
</div>

<script>
    function onSelect(args) {
        var uploadObj = document.getElementById("UploadFiles").ej2_instances[0];
        var totalSize = 0;
        for (var i = 0; i < args.filesData.length; i++) {
            var file = args.filesData[i];
            totalSize = totalSize + file.size;
        }
        var size = uploadObj.bytesToSize(totalSize);
        alert("Total select file's size is " + size);
    }
</script>
.control_wrapper {
    max-width: 400px;
    margin: 0 auto;
}

NOTE

You can also explore ASP.NET Core File Upload feature tour page for its groundbreaking features. You can also explore our ASP.NET Core File Upload example to understand how to browse the files which you want to upload to the server.