将一个Dropzone文件发送到多个网址 [英] Send one file of Dropzone to multiple urls

查看:86
本文介绍了将一个Dropzone文件发送到多个网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 Dropzone 一段时间了,并且效果很好。虽然,我不得不改变自己的方法。我曾经将文件发送到一个url(与Dropzone中一样),但是,我需要将其发送到多个url(同一个文件)。我找不到答案。有人知道原因吗?

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?

推荐答案

我认为dropzone中没有内置功能可以做到这一点,但是您可以为每个其他网址发送一个附加的 xmlhttprequest ,您可以在任何一个获得dropzone文件对象的事件中发送第二个请求。

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

        });
    }
};

这篇关于将一个Dropzone文件发送到多个网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆