简体   繁体   English

使用 Dropzone.js 上传订单

[英]Upload order with Dropzone.js

I am using Dropzone.js and my PHP script to upload files to my server.我正在使用Dropzone.js和我的 PHP 脚本将文件上传到我的服务器。 I am noticing that they don't exactly upload in the order I select them.我注意到它们并没有完全按照我选择它们的顺序上传。 For example, say I have 1.jpg , 2.jpg , 3.jpg , 4.jpg & 5.jpg .例如,假设我有1.jpg2.jpg3.jpg4.jpg5.jpg

They are uploaded in the order the server receives them the fastest.它们按照服务器最快接收它们的顺序上传。 So it could be uploaded like 4, 2, 5, 3, 1.所以它可以像 4、2、5、3、1 一样上传。

My PHP script also inserts the file into a database, which is why ordering is important.我的 PHP 脚本还将文件插入到数据库中,这就是排序很重要的原因。 I couldn't find a config option to upload in order, but I am thinking I might be able to step through the queue and upload them in order that way rather than letting dropzone handle the queue.我找不到按顺序上传的配置选项,但我想我可能能够遍历队列并按这种方式上传它们,而不是让 dropzone 处理队列。

parallelUploads set to 1 should help, but is a pretty big slow down depending on how many files/size of files to be uploaded. parallelUploads 设置为 1 应该会有所帮助,但根据要上传的文件数量/文件大小,速度会大大降低。

To get back parallelUploads, but have control over the order, you can pass a FileID back as the response from your upload url, and that can be read on dropzone's success event...要取回 parallelUploads,但要控制顺序,您可以将 FileID 作为来自上传 url 的响应传回,并且可以在 dropzone 的成功事件中读取...

dropzoneObject.on("success", function (file, response) {
    // Requires a hidden field named FileIDs to exist in your previewTemplate.
    $(file.previewElement)
        .find("input[name='FileIDs']")
        .val(response);
});

And after all uploads complete (queuecomplete event), you can post back FileIDs in the order that you want.在所有上传完成后(queuecomplete 事件),您可以按照您想要的顺序回发 FileID。

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

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