Dropzonejs - 上传前重命名文件重命名、上传、文件、Dropzonejs

2023-09-11 09:29:32 作者:妳吥嬞

我有悬浮窗的设置和工作与我的AWS的S3帐户。不过,我希望能够重命名文件,然后再发送给S3(追加时间戳为例),使上传具有相同的名称与现有文件的文件不会被覆盖。我试图抓住这个在发送事件,并在这一点上,但没有成功升级的文件名:

I have dropzone set-up and working with my AWS S3 account. However I want to be able to rename the file before it is sent to S3 (append with timestamp for example) so that a file uploaded with the same name as an existing file will not get overwritten. I've tried to catch this at the sending event and to update the file name at this point but without success:

this.on("sending", function(file) {
  file.name = 'my-new-prefix-' + file.name;
});

在任何地方我错了或这是为什么不工作思路?

Any ideas where I am going wrong or why this isn't working?

也已经提出了这个早些时候在 - https://github.com/enyo/dropzone/issues / 345

Also have raised this earlier at - https://github.com/enyo/dropzone/issues/345

推荐答案

我目前使用的 FromData() - Dropzone.js 它允许你发送自定义数据

I currently use FromData() - Dropzone.js which allows you to send custom data.

// with options.params = true;

this.on("sending", function(file) {
  formData.append("custom", "my-new-prefix-" + file.name);
});

我知道这不完全是你的问题,它只是一个临时的解决方案无需修改源$ C ​​$ C

I know this is not exactly what is your question, it is only a temporary solution without modifying the source code

您也可以直接在选项传递对象:

You can also pass object directly in options:

el.dropzone({
  params: {
    data: "data"
  }
});