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

Categories

I've been using Dropzone for a while and it works perfectly. Although, I had to change my approach. I used to send the file to an url (as usual in Dropzone), however, I need to send it to multiple urls (the same file). I couldn't find an answer. Some one know the reason?

See Question&Answers more detail:os

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

1 Answer

I don't think there is a built in feature in dropzone to do that, but you can send an additional xmlhttprequest for each additional url, you can send this second request in any event that gets the dropzone file object.

Here a bare minimum example sending it when the default upload was successful:

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);

        });
    }
};

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...