johnspackman / UploadMgr

Uploads files with background uploads and progress feedback on modern browsers
10 stars 14 forks source link

File size inconsistent between the stages #2

Closed dteleguin closed 8 years ago

dteleguin commented 8 years ago

The com.zenesis.qx.upload.File#size property seems to be floating between the upload stages; only the value reported at uploading stage is byte-precise. All the subsequent stages return file size + size of request headers. Here's a log excerpt (UploadMgr demo app, 116260127 byte file):

083557 uploadmgr.demo.Application[16-0]: Added file payara-4.1.1.161.zip 
083565 uploadmgr.demo.Application[16-0]: payara-4.1.1.161.zip: state=uploading, file size=116260127, progress=0
083796 uploadmgr.demo.Application[16-0]: Upload payara-4.1.1.161.zip: 1899907 / 116260624 - 2% 
083944 uploadmgr.demo.Application[16-0]: Upload payara-4.1.1.161.zip: 14286211 / 116260624 - 12% 
084191 uploadmgr.demo.Application[16-0]: Upload payara-4.1.1.161.zip: 20771307 / 116260624 - 18%
...
086077 uploadmgr.demo.Application[16-0]: Upload payara-4.1.1.161.zip: 116260624 / 116260624 - 100%
086581 uploadmgr.demo.Application[16-0]: payara-4.1.1.161.zip: state=uploaded, file size=116260624, progress=116260624

It would be more natural if the size property would be consistent between the stages and would always reflect the real file size.

derrell commented 8 years ago

The variable is called "size" in some browsers, and "fileSize" in others. Here's a bug fix I made years ago to fix this, that should probably be applied:

UploadButton.js near line 248 (in an ancient version of the code):

        control.addListener("change", function(e){
            var controlDom = control.getDomElement();
            this.__valueInputOnChange = true;            
            if (controlDom.files 
                && controlDom.files.length > 0 ){
                  this.setFileSize(
                    typeof controlDom.files[0].fileSize != "undefined"
                      ? controlDom.files[0].fileSize
                      : controlDom.files[0].size);
            }            
            var value = e.getData();
            this.setFileName(value);
            this.fireDataEvent('changeFileName',value);
        },this);
johnspackman commented 8 years ago

@derrell I think that fix must be for UploadWidget rather than UploadMgr - it's been a while but Im fairly sure that's not my code and the equivalent (in com.zenesis.qx.upload.XhrHandler) takes care of this already

@dteleguin 's issue is that the file size is reported incorrectly because of the headers, so UploadMgr counts the number of bytes and ends up seeing more than 100% of the file size getting uploaded

johnspackman commented 8 years ago

This is almost fixed in the current commit - "almost" because there is no way I can see to find the size of (or just get) the request headers, and as some request headers are provided by the browser the best we can do is approximate. Still, in my testing this gets to within <10 bytes accuracy, much better than the 450 bytes difference before