【问题标题】:Dropzone.js rename file after upload base on responseDropzone.js 根据响应上传后重命名文件
【发布时间】:2020-07-28 08:38:13
【问题描述】:

我正在想办法在上传后使用 dropzone.js 重命名文件,这样我以后可以通过发送正确的名称来删除它。

我现在拥有的:

this.on("success", function(file, responseText) {
   console.log(responseText); // responseText contains actual file name after server modifications
});

addRemoveLinks: true,
        this.on("removedfile", function(file) {
          var name = file.name;
          $.ajax({
            type: 'POST',
            url: 'delete_file.html',
            data: {
              'file-name': name,
            },
          });
        });

正如您在我的 ajax 数据中看到的那样,我正在发送初始文件名,而不是实际在服务器上的文件名(例如,如果有多个相同命名的文件,服务器将重命名它们)。 我一直在考虑在成功时更改 previewElement 名称:

file.previewElement.querySelector(".name").textContent = responseText;

然后在 ajax 中引用这个,但它看起来不像是一种优雅的方法。

另一种选择是创建一个带有 映射的地图,但我不确定这是否是矫枉过正。

您如何建议在上传后访问新文件名?

【问题讨论】:

    标签: javascript dropzone.js


    【解决方案1】:

    我想出的最简洁的选项是使用 file.xhr.response 值,它包含新名称而不是 file.name

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-02-25
      • 2014-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-21
      • 2016-12-02
      相关资源
      最近更新 更多