Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
409 views
in Technique[技术] by (71.8m points)

javascript - Send one file of Dropzone to multiple urls

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

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

1 Reply

0 votes
by (71.8m points)

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

        });
    }
};

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...