使用 paramName 键多次上传

multiple uploads with paramName keys

我需要上传多个文件,服务器需要一个 uuid 作为键。

files[cd43fbad-305e-430c-a25c-8f0d7eabbd66]
files[4fa59bc2-c44f-40e0-b793-66a48d6abcb1]
files[56ce2264-6f7e-4824-a0aa-d28631784dda]

然而,对于 dropzone,似乎只有 files 部分是可变的。可以以某种方式挂钩它为多个文件附加 [] 的方式吗?

我遇到了类似的问题,我解决了。

您可以像下面这样重写 js 代码。 在 return 语句中添加您的代码。

Dropzone.prototype._getParamName = function(n) {
            if (typeof this.options.paramName === "function") {
                return this.options.paramName(n);
            } else {
//                return "" + this.options.paramName + (this.options.uploadMultiple ? "[" + n + "]" : "");
                return "" + this.options.paramName;
            }
        };

执行此操作的正确方法是使用函数覆盖 paramName 选项。

示例:

    new Dropzone("#image-dropzone", {
        autoProcessQueue: false,
        parallelUploads: 20,
        maxFiles: 20,
        uploadMultiple: true,
        acceptedFiles: "image/jpeg,image/png,image/gif",
        paramName: function(n) {
            uuid = "do whatever you need to find the uuid";
            return "file[" + uuid + "]";
        },
    });