我正在为我的网站使用dropzone.js,并尝试在上传之前重命名文件。最近dropzone添加了新的函数renameFile,但我无法使用它。这是一个bug,还是我对函数的理解有误?
未调用console.log()。
Dropzone.myDropzone = false;
var size = 1;
Dropzone.options.myDropzone = {
maxFilesize: size,
renameFile: function(file){
console.log("I was called");
return "newname.pdf";
},
paramName: "pdffile",
url: "UploadServlet",
acceptedFiles: "application/pdf",
dictDefaultMessage: "Ziehe Dateien hierhin zum Hochladen",
dictFallbackMessage: "Dieser Browser wird leider nicht unterstützt",
dictFileTooBig: "Die Datei ist leider zu groß. Erlaubtes Maximum sind " +size +" MB",
dictInvalidFileType: "Dies ist leider der falsche Dateityp. Es werden nur PDF-Dateien unterstützt",
sending: function (file,xhr,formData){
formData.append("dateiname",file.name);
}
}发布于 2018-06-15 06:14:25
这是我刚刚开始工作的代码。目前,文档根本不正确。file.upload.filename只是不断抛出错误。它说旧的方法也被贬低了。
我的整个街区:
<form id="my-dropzone" action="upload.php" class="dropzone"></form>
<script src="/sci/dropzone.js"></script>
<script>
Dropzone.options.myDropzone = {
chunkSize: 5000000,
retryChunks: true,
retryChunksLimit: 2,
chunking: true,
timeout: 60000,
maxFilesize: 1000,
dictDefaultMessage: "Click or Drag/Drop files here to upload",
renameFile: function(file) {
return file.name = "NAME-PREFIX_" + file.name;
},
init: function() {
this.on("uploadprogress", function(file, progress) {
console.log("File progress", progress);
});
this.on("success", function(file) {
console.log(file["name"]);
});
}
}
</script>注意我放了一个前缀。在我的代码中,我添加了days日期(通过PHP,因为它不依赖于客户端具有正确的时间)
renameFile: function(file) {
return file.name = "NAME-PREFIX_" + file.name;
},假设你的文件是"me.jpg“,你会得到"NAME-PREFIX_me.jpg”
https://stackoverflow.com/questions/46515733
复制相似问题