Blueimp upload plugin progressbar error
Asked Answered
T

1

2

I have a form where I am uploading files using the blueimp upload plugin. The upload process work ok. All I want is to add a progress bar to the upload event. I have tried using the progressall callback specified in the blueimp documentation but all I get is 100% loaded, as data.loaded is always equal to data.total.

I have seen that the plugin handles the progressall callback only after the done callback, and inside the done callback I have several actions taking place.

See sample below:

$("#uploadFile" + docId).fileupload({
        url: my url to the upload script, 
        dataType : 'json',
        type: 'POST',
        formAcceptCharset: 'utf-8',
        forceIframeTransport: true,
        progressInterval: 100,
        bitrateInterval: 500,
        autoUpload: true,
        progressall: function (e, data) {
            var progress = parseInt(data.loaded / data.total * 100, 10);
            $('#progress'+docId+' .bar').css(
                'width',
                progress + '%'
            ).text(progress + '%');
        },
        send : function(e, data) {
            if(data.files[0].size <= 9000000000){
                var docId = $(this).attr("data-course-id");
                $("#uploadFileForm"+docId+" .uploadProgress").removeClass("hidden");
                $("#uploadFeedback").html("");
            }else{
                $("#uploadFeedback").html(file is too big);
                return false;
            }
        },
        fail : function(e, data) {
            console.log("error = " + data.errorThrown);
            return false;
        },
        done : function(e, data) {      
            var metaSuggestions = data.result;

            $("#uploadFileForm"+docId+" .uploadProgress").addClass("hidden");

            //enable save button
            $("#fileUploadSubmit"+ docId).removeClass("buttonDisabled");
            $("#fileUploadSubmit"+ docId).removeAttr("disabled");

            //populate fields
            $("#fileUploadedId"+docId).val(metaSuggestions.uploadedDocId);
            $("#fileDuration"+docId).val(metaSuggestions.lengthMiliseconds/1000 + " s");
            $("#fileMediaType"+docId).val(metaSuggestions.mediaType);

            //change cancel action
            $("#fileUploadCancel"+ docId).unbind("click").click(function(){

                var successCallbackCancel = function(data){
                    $("#uploadFileForm"+ docId).addClass("hidden");
                }

                var errorCallbackCancel = function(error){
                    console.log(error);
                }

                cancelAddFile(contextPath, docId, metaSuggestions.uploadedDocId, successCallbackCancel, errorCallbackCancel);
            }); 

            $("#fileUploadSubmit"+docId).unbind('click').click(function(){

                var successCallbackSubmit = function(data){
                    $("#uploadFileForm" + docId).addClass("hidden");

                    //append file to files container
                    var fileContainer = $("#files" + docId);

                    appendFilesToContainer(data, docId);
                }

                var errorCallbackSubmit = function(error){
                    console.log(error);
                }

                submitFiles(contextPath, docId, metaSuggestions, successCallbackSubmit, errorCallbackSubmit);
            });
            console.log("file done");
       }
    });
Toitoiboid answered 3/6, 2013 at 10:43 Comment(0)
T
2

I managed to fix it by commenting out forceIframeTransport: true. Now the progress bar works perfectly!

Toitoiboid answered 3/6, 2013 at 13:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.