Dropzonejs - rename file before upload

2019-05-17 08:16发布

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?

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

1条回答
姐就是有狂的资本
2楼-- · 2019-05-17 08:58

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);
});

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"
  }
});
查看更多
登录 后发表回答