繁体   English   中英

Dropzone js 使用新函数 dropzone renameFIle

[英]Dropzone js using new function dropzone renameFIle

我正在为我的网站使用 dropzone.js 并尝试在上传之前重命名文件。 最近dropzone添加了新函数renameFile,我无法开始工作。 这是一个错误还是我理解错误?

没有调用 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);
}

}

这是我刚开始工作的代码。 目前,文档绝不是正确的。 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>

注意我加了一个前缀。 在我的代码中,我添加了日期(通过 PHP,因为它不依赖于具有正确时间的客户端)

    renameFile: function(file) {
        return file.name = "NAME-PREFIX_" + file.name;
    },

假设你的文件是“me.jpg”,你会得到“NAME-PREFIX_me.jpg”

暂无
暂无

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

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