Upload progress bar amazon s3

0

I'm using the following code that sends the post with the $ _FILE file to a file I called upload.php, which makes use of amazon's sdk php. The upload is occurring normally, but I noticed that the progress bar goes to 100% without first having sent the file to my bucket which causes some confusion for the system user.

I'm using the following code in jquery:

    $("#uploadFiles").submit(function(event) {
    //Para evento padrão de submit
    event.preventDefault();
    //Pega referencia a barra de progresso
    var progressBar = $(".progress-bar");
    //Busca o form de upload e o retorna como um objeto
    var form = document.getElementById("uploadFiles");
    var formData = new FormData(form);

    $.ajax({
        type: 'POST', //Or 'GET',
        url: '../funcoes/upload.php',
        data: formData,
        contentType: false, 
        processData: false, 
        xhr: function() {
            var xhr = $.ajaxSettings.xhr();
            if(xhr.upload){
                xhr.upload.addEventListener("progress", function(evt) {
                    if (evt.lengthComputable) {
                        progressBar.css("visibility", "visible");
                        var percentComplete = evt.loaded / evt.total;
                        var progresso = Math.round(percentComplete * 100) + "%";
                        //Adiciona texto com progresso na div
                        //progressBar.empty().append(progresso);
                        //Aumenta tamanho da div conforme progresso
                        progressBar.width(progresso);
                    }
                }, false);
            }
            return xhr;
        },
        dataType: 'json',
        success: function(data) {
            //Limpa texto de progresso e volta barra pro inicio
            progressBar.empty().width('0%');
            //Coloca a barra de progresso invisivel
            progressBar.css("visibility", "hidden");
        }
    });

});

How do I resolve this?

    
asked by anonymous 26.12.2017 / 22:28

0 answers