TTLabs / EvaporateJS

Javascript library for browser to S3 multipart resumable uploads
1.82k stars 207 forks source link

Progress fluctuating #398

Open mustafah opened 6 years ago

mustafah commented 6 years ago

I have standard file uploading code like the following, and it is uploading correctly but the progressValue is not growing ascendingly , it can get less then more again ! Is that normal behaviour ?

    return Evaporate.create(config)
        .then(function (evaporate) {
            var addConfig = {
                name: file.name,
                file: file,
                contentType: file.type,
                started: function(file_key) {
                },
                progress: function (progressValue) {
                    // progressValue is fluctuating, it can be 0.95 then 0.8 !
                },
                complete: function (_xhr, awsKey) {
                }
            };

            evaporate.add(addConfig, {})
                .then(function (awsObjectKey) {
                    console.log('File successfully uploaded to:', awsObjectKey);
                },
                function (reason) {
                    console.log('File did not upload sucessfully:', reason);
                });
        });
mustafah commented 6 years ago

I discovered the reason, actually I was executing the event handler (which has the uploading with evaporateJS) twice !, because I am using rails turbolinks so eventually I had to do something like the following:

$(window).on('load turbolinks:load', function () {
    $('.custom-file-input').off('change').on('change', function () {
        evaporateFile(this, {
                progress: function (progressValue) {
                },
                complete: function (url) {
                    console.log(url);
                }
            }
        );
    });
});

Thank you ...