2016-11-22 14 views
-2

私はしばらくの間Dropzoneを使用していました。しかし、私は私のアプローチを変えなければならなかった。私は(通常Dropzoneのように)URLにファイルを送信するために使用しましたが、複数のURL(同じファイル)に送信する必要があります。私は答えを見つけることができませんでした。理由を知っている人もいますか?Dropzoneの1つのファイルを複数のURLに送信

答えて

0

私はdropzoneにそれを行う機能はないと思いますが、追加のURLごとにさらにxmlhttprequestを送ることができます。この場合、この2番目のリクエストはdropzoneファイルオブジェクトを取得するすべてのイベントで送信できます。ここで

デフォルトのアップロードが成功したときにそれを送る必要最低限​​例:

JS:

Dropzone.options.myDropzone = { 

    // This is the default dropzone url in case is not defined in the html 
    url: 'upload.php', 

    init: function() { 

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

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

      // Creat a new xmlhttprequest with the second url 
      secondRequest = new XMLHttpRequest(); 
      secondRequest.open('POST', 'upload2.php', true); 

      // Just to see second server response on success 
      secondRequest.onreadystatechange = function() { 
       if(secondRequest.readyState === XMLHttpRequest.DONE && secondRequest.status === 200) { 
        console.log(secondRequest.responseText); 
       } 
      }; 

      // Create a new formData and append the dropzone file 
      var secondRequestContent = new FormData(); 
      secondRequestContent.append('file', file, file.name); 

      // Send the second xmlhttprequest 
      secondRequest.send(secondRequestContent); 

     }); 
    } 
}; 
+0

おかげであなたの応答をwallek876。 しかし、私は 'addedfile'イベントで画像base64を使用して終了し、そこから関数を呼び出しました。 – Pedro

関連する問題