您也可以用下面的代码:
<script>
Dropzone.options.myAwesomeDropzone = false;
Dropzone.autoDiscover = false;
$("#image").dropzone({
url: "http://someserver.com/upload.php",
paramName: "image", // The name that will be used to transfer the file
maxFilesize: 2, // MB
maxFiles: 5,
parallelUploads: 5,
addRemoveLinks: true,
dictMaxFilesExceeded: "You can only upload upto 5 images",
dictRemoveFile: "Delete",
dictCancelUploadConfirmation: "Are you sure to cancel upload?",
accept: function (file, done) {
console.log(file)
if ((file.type).toLowerCase() != "image/jpg" &&
(file.type).toLowerCase() != "image/gif" &&
(file.type).toLowerCase() != "image/jpeg" &&
(file.type).toLowerCase() != "image/png"
) {
done("Invalid file");
}
else {
done();
}
},
init: function() {
var mockFile = { name: "myimage.jpg", size: 12345, type: 'image/jpeg' };
this.addFile.call(this, mockFile);
this.options.thumbnail.call(this, mockFile, "http://someserver.com/myimage.jpg");
}
});
</script>
编辑
由于悬浮窗4.0 init
功能的更新可以被称为:
init: function() {
var mockFile = { name: "myimage.jpg", size: 12345, type: 'image/jpeg' };
this.options.addedfile.call(this, mockFile);
this.options.thumbnail.call(this, mockFile, "http://someserver.com/myimage.jpg");
mockFile.previewElement.classList.add('dz-success');
mockFile.previewElement.classList.add('dz-complete');
}
值得注意的是,使用此方法添加的文件与“常规”文件的行为有些不同。首先,在dropzone实例上调用.removeAllFiles()时,我似乎无法摆脱它们。我发布这个作为一个问题,以防万一有人想贡献:http://stackoverflow.com/questions/23369291/dropzone-js-removeallfiles-does-not-remove-mock-files –
这是因为你实际上没有添加任何文件到文件数组。使用thisDropzone.files.push(mockFile); – Dan
@dan在哪里添加推送功能,我在thumbnail.call下面添加,但它不工作。 –