Hi,
I am using the file upload template to customize the file upload. Currently Async is set to false, so on select event I am displaying the template. But I want to use the in built function which displays the file size. I am using the below template but I don't want to display the file size in bytes. Is there a way I can achieve this? I created a custom function called formatFileSize() but I want to utilize the inbuilt function if available.
<script id="uploadFileTemplate" type="text/x-kendo-template">
<div>
<span class="k-file-extension-wrapper">
<span class="k-file-extension">#=files[0].extension#</span>
<span class="k-file-state"></span>
</span>
<span class="k-file-name-size-wrapper">
<span class="k-file-name" title="#=name#">#=name#</span>
<span class="k-file-size">#=formatFileSize(size,2)#</span>
</span>
<button id='btnFileDelete' type='button' class='k-upload-action' style='position: absolute; right: 0;' title="Delete">
<span title="Remove" class="k-icon k-i-close k-i-x" aria-label="Remove"></span>
</button>
</div>
</script>
<script type="text/javascript">
function OnSelectUploadFile(e) {
setTimeout(function () {
$('#btnFileDelete > span').addClass('btnFileOverwrite');
$('#btnFileDelete > span').attr('title', 'Delete the file');
$('#btnFileDelete > span').text('Delete');
$('#btnFileDelete').prepend('<i class="fas fa-times"></i>');
});
return true;
}
function formatFileSize(bytes,decimalPoint) {
if(bytes == 0) return '0 KB';
var k = 1000,
dm = decimalPoint || 2,
sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
}
</script>
I am using the below version of Kendo Mvc
2017.3.1018.545