简体   繁体   English

Dropzone.js-仅显示完整上传的进度

[英]Dropzone.js - only show progress of complete upload

I'm using dropzone.js to upload files to my server. 我正在使用dropzone.js将文件上传到服务器。 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 complete 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. 编辑 :可选点是以引导程序模式显示此进度栏,因此当您上传内容时,它不会更改网站上的任何内容。

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: 我认为dropzone需要某种对象,因此基本上可以通过将dropzone初始化中的PreviewTemplate选项设置为div而不包含任何内容来完成此操作:

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

The other part is the progress bar. 另一部分是进度条。 To accomplish 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: 然后,使用dropzone中的totaluploadprogress事件来更新进度条上的进度:

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. 当然,还需要进行其他清理,例如何时隐藏总进度条等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM