Search results

Get the total size of selected files

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.

razor
file-size.cs
<div class="control_wrapper">
    @Html.EJS().Uploader("UploadFiles").Selected("onSelect").AsyncSettings(new Syncfusion.EJ2.Inputs.UploaderAsyncSettings { SaveUrl = "https://aspnetmvc.syncfusion.com/services/api/uploadbox/Save", RemoveUrl = "https://aspnetmvc.syncfusion.com/services/api/uploadbox/Remove" }).Render()
</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>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace EJ2CoreSampleBrowser.Controllers.TextBoxes
{
    public partial class UploaderController : Controller
    {
        public ActionResult DefaultFunctionalities()
        {
            return View();
        }
    }
}