简体   繁体   中英

Same name for all files uploaded with Dropzone.js

I have a problem with dropzone: all file names are the same when uploaded to remote.

Here is my code :

var AUTH_TOKEN=$('meta[name="csrf-token"]').attr('content');

      Dropzone.autoDiscover = false;
      var myDropzone = new Dropzone("div#mydropzone",{
          url: "<%= professionnel_diagnostiqueur_diagnostiqueurdevi_diagnostiqueurreponses_path(@devi.diagnostiqueur.professionnel.id,@devi.diagnostiqueur.id,@devi.id) %>",
          autoProcessQueue: false,
          uploadMultiple: true,
          addRemoveLinks:true,
          parallelUploads:10,
          maxFilesize: 15,
          params:{
              'authenticity_token':  AUTH_TOKEN
          },
          successmultiple: function(data,response){
              $('#msgBoard').append(response.message).addClass("alert alert-success");
              $('#msgBoard').delay(2000).fadeOut();
              $('#fileslist').val(response.filesList);
              $('#photographedit').off('submit').submit();
          }
      });

      $('#photographedit').submit(function(e){
          if(myDropzone.getQueuedFiles().length > 0){
              e.preventDefault();
              myDropzone.processQueue();
          }
      });

There is this thread: Dropzone uploaded file have same name But it is unanswered

And this thread that suggests adding a hidden field : https://github.com/enyo/dropzone/issues/580

Though I am yet noob with JS. Could someone help me factor the right code to add a hidden field for my above code? The dragndrop is located on id mydropzone and form has id photographedit

You can change file name before sending the file to the server

myDropone.on('processingfile', function(file) {
  file.name = file.name + Math.floor(Date.now() / 1000);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM