javascript - Dropzone.js - only show progress of complete upload - Stack Overflow

I'm using dropzone.js to upload files to my server. That's how the file looks like:<div id

I'm using dropzone.js to upload files to my server. That's how the file looks like:

<div id="full_site">
    <form id="uploadFile" method="post" name="uploadFile" action="upload.php"
          class="dropzone needsclick dz-clickable full-height">
        <span id="tmp-path"></span>
        <div class="dz-message"><b></b></div>
    </form>
</body>


<script>
    $(document).ready(function () {
        Dropzone.autoDiscover = false;

        Dropzone.options.uploadFile = {
            init: function () {
                this.on("success", function (file, responseText) {
                    file.previewTemplate.appendChild(document.createTextNode(responseText));
                });

                this.on("sending", function (file) {
                    $("#tmp-path").html('<input type="hidden" name="path" value="' + file.fullPath + '" />')
                });
            }
        };

        var myDropzone = new Dropzone("#uploadFile", {
            url: "upload.php"
        });
    });
</script>

What I try to achieve is, that there are no upload previews shown any more, so they are no previews for each file any more, but a progress bar, that show's the overall process of the plete upload (maybe only show an error if there is one, but otherwise do not show every single item). Is there any way I can achieve this?

Edit: an optional point would be to show this progress bar in a bootstrap modal, so it doesn't change anything on the site when you upload something.

I'm using dropzone.js to upload files to my server. That's how the file looks like:

<div id="full_site">
    <form id="uploadFile" method="post" name="uploadFile" action="upload.php"
          class="dropzone needsclick dz-clickable full-height">
        <span id="tmp-path"></span>
        <div class="dz-message"><b></b></div>
    </form>
</body>


<script>
    $(document).ready(function () {
        Dropzone.autoDiscover = false;

        Dropzone.options.uploadFile = {
            init: function () {
                this.on("success", function (file, responseText) {
                    file.previewTemplate.appendChild(document.createTextNode(responseText));
                });

                this.on("sending", function (file) {
                    $("#tmp-path").html('<input type="hidden" name="path" value="' + file.fullPath + '" />')
                });
            }
        };

        var myDropzone = new Dropzone("#uploadFile", {
            url: "upload.php"
        });
    });
</script>

What I try to achieve is, that there are no upload previews shown any more, so they are no previews for each file any more, but a progress bar, that show's the overall process of the plete upload (maybe only show an error if there is one, but otherwise do not show every single item). Is there any way I can achieve this?

Edit: an optional point would be to show this progress bar in a bootstrap modal, so it doesn't change anything on the site when you upload something.

Share Improve this question asked Apr 12, 2016 at 7:01 user5638730user5638730 5452 gold badges10 silver badges23 bronze badges 0
Add a ment  | 

1 Answer 1

Reset to default 4

There are a couple parts to this. First, you want to avoid having any preview template for items that have been queued or are uploading. I think dropzone needs some kind of object, so you can basically do this by setting the previewTemplate option in the dropzone initialization to a div with nothing inside of it:

var myDropzone = new Dropzone("#uploadFile", {
    url: "upload.php",
    previewTemplate: "<div></div>"
});

The other part is the progress bar. To acplish this, you could add an event listener for addedfile to create your progress bar

myDropzone.on("addedfile", function (file) {
     // Build progress bar here
});

Then, use the totaluploadprogress event from dropzone to update the progress on your progress bar:

myDropzone.on("totaluploadprogress", function(progress) {
    // Update progress bar with the value in the variable "progress", which 
    // is the % total upload progress from 0 to 100
});

Hopefully this points you in the right direction. There will of course be other cleanup needed, like when to hide the total progress bar, etc.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744281870a4566607.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信