blueimp/jQuery-File-Upload — Issue #1002: _formatFileSize is no accurate
Author: insomnix
Created: 2012-02-10 08:18:46+00:00
State: open

I noticed that the size of the files returned is a little off. Not a big deal, here is the change I made and it reflects the size more accurately to what's on disk. I also added 'bytes = parseInt(bytes);' because, for some reason, the size was coming back as a string ( probably because I'm mucking around with the code ). This solves that potential problem in the future. Feel free to add to your code. Great project, Thanks.

_formatFileSize: function (bytes) {
bytes = parseInt(bytes);
if (typeof bytes !== 'number') {
return '';
}
if (bytes < 1024) {
return bytes.toFixed(2) + ' B';
}
if (bytes < 1048576) {
return (bytes / 1024).toFixed(2) + ' KB';
}
if (bytes < 1073741824) {
return (bytes / 1048576).toFixed(2) + ' MB';
}
return (bytes / 1073741824).toFixed(2) + ' GB';
},