LPology / Simple-Ajax-Uploader

Javascript file upload plugin with progress bar support. Works in all major browsers, including IE7+, Chrome, Firefox, Safari, and Opera. No dependencies - use it with or without jQuery.
995 stars 267 forks source link

File size is always represented in KB.. #186

Open MrCaspan opened 7 years ago

MrCaspan commented 7 years ago

Is there any way that you can add a function that will give the proper reduces file size? 109834K is confusing for an end user instead of 109 MB

MrCaspan commented 7 years ago

Anyone?? Is this project even active anymore?

MrCaspan commented 7 years ago

I took matters into my own hands and created the code myself

for anyone looking to add this to their min project please add this function to the beginning of the min file after the comment but before the !function(e,t){... function fB(b,d){if(b==0)return 0;var k=1000,dm=d+1||3,s=['Bytes','KB','MB','GB','TB','PB','EB','ZB','YB'],i=Math.floor(Math.log(b)/Math.log(k));return parseFloat((b/Math.pow(k,i)).toFixed(dm))+' '+[i];}

then search for p=Math.round(p/1024) and replace it with p=fB(p,1)

and then find i=Math.round(e[o].size/1024) an replace it with i=fB(e[o].size,1)

this will then give you a proper readout for your Bytes, KB, MB, GB etc..

JubaDZ commented 6 years ago
var
lang: 'en',
----------------------------------------------------------------------------------------
ss.formatBytes = function(bytes,lang) {

    if(lang==='ar')
        var sizes = ["بايت", "كيلو", "ميقا","جيقا","تيرا"]; 
    else
        var sizes = ["Bytes", "KB", "MB","GB","TB"]; 

   var k = 1024;
   var i = Math.floor(Math.log(bytes) / Math.log(k));
   return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i+1];
};
----------------------------------------------------------------------------------------
if ( size && !self._sizeFlags[key] ) {
                            if ( sizeBox ) {
                                sizeBox.innerHTML = ss.formatBytes(size,this._opts.lang);

                            }
----------------------------------------------------------------------------------------
 // Inject file size into size box
        if ( sizeBox ) {
            sizeBox.innerHTML = ss.formatBytes(fileObj.size,this._opts.lang);
        }