2016-11-22 81 views
-2

我一直在使用Dropzone一段時間,它完美的工作。雖然,我不得不改變我的方法。我曾經發送文件到一個URL(像Dropzone一樣),但是,我需要將它發送到多個URL(同一個文件)。我找不到答案。有人知道原因?發送一個Dropzone的文件到多個網址

回答

0

我不認爲在dropzone中有內置功能可以做到這一點,但是您可以爲每個額外的url發送額外的xmlhttprequest,您可以在任何獲取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

相關問題