2017-01-12 1 views
0

中に現在のファイル名を表示します。ドロップゾーン:私は次のコードでdropzone.jsで複数のファイルをアップロードしながら、現在のファイル名を表示したいアップロード

dropzone.on("uploadprogress", function(file, parameter, bytes){ 

    //update progressbar, that works    
    $('#progress').css("width", parameter + "%").html(parseInt(parameter) + " %");  

    //prints the correct filenames 
    console.log(file.name); 

    //does not work: only last file.name in queue is shown, 
    //even in a real server environment where i upload many files 
    $('#currentFile').html(file.name);   

}); 

HTML:それはどのように行われるか

<div class="progress-bar" id="progress"/></div>    
<span id="currentFile"></span> 

、currentFileは実際にアップロードされた現在のファイルと一致していますか?前もって感謝します。

+0

私は考えることができる唯一の解決策は、ドロップゾーンは、一度に1つのファイルをアップロードすることです、私はここfalseからautoProcessQueueセット、例を挙げて、手動でアップロードプロセスを開始すると仮定しています私は知っているので、値をセキュリティ上の理由からdomから変更することはできません。ファイル名を表示するには、別のdivを実装してアップロードしたファイルを表示する必要があります。 –

+0

hm - しかし、私はを変更しません。スパン '#​​currentFile'には表示機能があります。アップロード自体は別のdivにあります。 – Steve

+0

多分これを試してみてください:http://www.dropzonejs.com/#event-sending –

答えて

1

あなたのコードはうまくいくはずです。私が見る唯一の問題は、ファイルが同時にアップロードされていることです。表示されるファイルは、異なるファイル間で切り替えることができます。uploadProgressイベントは、これは重複する可能性があります。このため、最後にアップロードされたファイルのデータしか表示されません。限り

Dropzone.options.myDropzone = { 
    url: 'yourUrl', 
    autoProcessQueue: false, 
    parallelUploads: 1, 
    init: function() { 
     var mydrop = this; // Closure 

     // This is the event listener that triggers the start of the upload 
     $('#yourSubmitButtonId').on('click', function(){ 
      mydrop.processQueue(); 
     }); 

     this.on('success', function(file){ 

      // Just to see default server response on console 
      console.log(file.xhr.responseText); 

      // Continue processing the queue if there are still files pending 
      if (this.getQueuedFiles().length > 0) { 
       this.processQueue(); 
      } else { 
       console.log('Job done'); 
      } 

     }); 

     this.on('uploadprogress', function(file, parameter, bytes){ 

      //update progressbar, that works    
      $('#progress').css("width", parameter + "%").html(parseInt(parameter) + " %");  

      //prints the correct filenames 
      console.log(file.name); 

      //does not work: only last file.name in queue is shown, 
      //even in a real server environment where i upload many files 
      $('#currentFile').html(file.name);   

     }); 
    } 
}; 
+0

あなたには決定的な説明があります。私はそのようなことを念頭に置いていました。実際には1つのファイルだけをアップロードするときに期待どおりに動作します。私は、各ファイルを別々にアップロードする必要はないので、選択したすべてのファイルを一度アップロードするという要件があります。 – Steve

+0

一度に1つずつアップロードしても、すべてが一度にアップロードされた場合と同じ感じになります。この場合に何をする必要があるのか​​は、サーバー側のすべてのファイルをまとめてまとめたものです。さもなければ私はdropzoneであなたが望む振る舞いを達成することは可能ではないと思います。 – wallek876

+0

ああ申し訳ありませんが、私は少し誤解しました。あなたの上記のコードでは、もちろん、私は一度に複数のファイルをアップロードすることができますが、各ファイルの新しいサーバー通信が行われます。とった。まあ、あなたの提案が働いて、私は今それを使用します。ありがとう。 – Steve

関連する問題