Dropzone.js v4 + - 显示服务器上的现有文件,限制文件数和其他功能

时间:2015-07-25 13:50:07

标签: javascript dropzone.js

如何将服务器上的现有文件添加到dropzone,并正确地工作所有功能和正确的样式?

1 个答案:

答案 0 :(得分:6)

我写了一个添加文件的函数:addCustomFile(file,thumbnail_url,responce)

由版本支持:4.0.1稳定

正确工作:maxFiles限制,事件maxfilesexceeded,事件成功和其他

$("#dropzone-images").dropzone({
    url: "...",
    paramName: 'image_temp',
    maxFiles: 1,
    init: function () {
        this.addCustomFile = function(file, thumbnail_url , responce){
            // Push file to collection
            this.files.push(file);
            // Emulate event to create interface
            this.emit("addedfile", file);
            // Add thumbnail url
            this.emit("thumbnail", file, thumbnail_url);
            // Add status processing to file
            this.emit("processing", file);
            // Add status success to file AND RUN EVENT success from responce
            this.emit("success", file, responce , false);
            // Add status complete to file
            this.emit("complete", file);
        }

        this.addCustomFile(
            // File options
            {
                // flag: processing is complete
                processing: true,
                // flag: file is accepted (for limiting maxFiles)
                accepted: true,
                // name of file on page
                name: "The name",
                // image size
                size: 12345,
                // image type
                type: 'image/jpeg',
                // flag: status upload
                status: Dropzone.SUCCESS
            },
            // Thumbnail url
            "http://.../img.jpg",
            // Custom responce for event success
            {
                status: "success"
            }
        );
    }
});