Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

jquery - Uploading multiple files with the same file.name using dropzone.js

I'm implementing dropzone.js and everything is perfect until I try to upload multiple files with the same name, let's say uploading photos from an iOS device where all have the same name: image.jpg, I can change the file name in my php code but the problem is that is no longer accessible in dropzone for example, to delete a photo uploaded, because I will end with two different names one in the file renamed with my php and the other in dropzone.

So, anyone can help me with that? There's a way to rename the file before upload with js?

Thanks,

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Did you set paramName correctly? And you need to remember that Dropzone will add [] to this field if uploadMultiple is true, so you can get the values through an array named by your paramName.

But if you want to rename anyway you could try this:

Dropzone.options.myAwesomeForm = {
  paramName: "file",
  uploadMultiple: true,
  parallelUploads: 1,
  //[more configuration]

  init: function() {
    var myDropzone = this;

    //[some code]

    this.on("sending", function(file, xhr, formData) {
      var name = "name-you-want-and-should-be-unique";
      formData.append(name, file);
    });

    //[some more code]
  }
}

Note that I set parallelUploads to 1 so the name you want won't be replaced. But if you do want more you should put an data-id to every file you add through listening to event "addedfile" and then take it when you send the file through "sending".

I hope you find it useful :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...