如何在上传前更改 dropzone 中的 File.Name

How can I change File.Name in dropzone before uploading

在下面的代码中,我有两个控制器,即 upload/post 和 document/post,当它在 API 上传输时,保存 file.name 的难度很小由于秒数,有时两者不匹配例如数据库一个是 file20170801053331.jpg 上传的图片将是 file20170801053332.jpg 因此,两个不匹配所以我打算将文件名传输到上传控制器所以它是一样的但是 file.name 不能改变。

   const req = request.post('http://localhost:8933/api/upload/post');
            acceptedFiles.forEach(file => {


                var now = new Date().toLocaleString('en-PH');
                form.State = 1;
                var cdate =dateFormat(now, "yyyymmddHHMMs")
                var ext = file.name.split(".").slice(-1)[0];
                var ext2 = file.name.split("."+ext).slice(0)[0];
                var fileNames = (ext2+cdate+"." +ext);
                form.Link=fileNames;
                form.Name=file.name;
                file.name = fileNames; // this is what im trying to do but it wasnt working  
                req.attach(file.name, file);
                this.props.post('document/post', form);
            });
                req.end(callback);

您可以通过在 req.attach

上添加新名称来更改 file.name
    var name =  form.something.length;
    var acceptedFiles = form.passFile;
    const req = request.post('http://localhost:8933/api/upload/post');
    acceptedFiles.forEach(file => {
        form.State = 1;
        var cdate =uuidv1();
        var ext = file.name.split(".").slice(-1)[0];
        var ext2 = file.name.split("."+ext).slice(0)[0];
        var fileNames = (ext2+cdate+"." +ext); // call this and put it on the req.attach
        form.Link=fileNames;
        form.Name=file.name;
        req.attach(file.name, file, fileNames);
        this.props.post('document/post', form);

    });