Javascript jQuery文件上传,带拖放功能;drop提交空文件输入

Javascript jQuery文件上传,带拖放功能;drop提交空文件输入,javascript,jquery,file-upload,Javascript,Jquery,File Upload,我使用的是jQuery fileupload插件,它在上传文件时非常有效,方法是单击文件输入并通过浏览器对话框选择 但是,当使用拖放时,它似乎提交了一个空文件输入 ------WebKitFormBoundaryCA4VuYwsPr7h4ItR Content-Disposition: form-data; name="attachment"; filename="" Content-Type: application/octet-stream 尽管fileupload的add回调中的数据对象

我使用的是jQuery fileupload插件,它在上传文件时非常有效,方法是单击文件输入并通过浏览器对话框选择

但是,当使用拖放时,它似乎提交了一个空文件输入

------WebKitFormBoundaryCA4VuYwsPr7h4ItR
Content-Disposition: form-data; name="attachment"; filename=""
Content-Type: application/octet-stream
尽管fileupload的add回调中的数据对象在调用data.submit()之前确实有一个文件

有人知道为什么会这样吗

编辑:代码:

$(document).bind('drop.fileUpload', function (e) {
    if(jQuery(e.target).attr('id') !== 'dropZone'){
        return;
    }

    var fileInput = jQuery('#attachment');
    var files = e.originalEvent.dataTransfer.files;

    if (fileInput.length && files.length) {
        jQuery('#dropZone').hide();
        fileInput.fileupload('add', {files: files});

        e.preventDefault();
    }
});

jQuery('.js_toggleFileupload').fileupload({
    autoUpload: true,
    forceIframeTransport: true,
    progressInterval: 50,
    url: '/xhr',
    add: function (e, data) {

        console.debug(data); // this is where the data object has files

        var jqXHR = data.submit().done(function (e, data) { // this is where an empty file input is submitted
            //stuff happens here
        }
    }
}); 

哦!问题是同时使用iframeTransport和拖放,这无法工作,因为iframeTransport选项将文件输入发布到iframe。在拖放的情况下,文件输入有一个空值


我已经关闭了forceIframeTransport选项,现在它可以工作了。

请添加您的javascript代码。
$(document).bind('drop.fileUpload', function (e) {
    if(jQuery(e.target).attr('id') !== 'dropZone'){
        return;
    }

    var fileInput = jQuery('#attachment');
    var files = e.originalEvent.dataTransfer.files;

    if (fileInput.length && files.length) {
        jQuery('#dropZone').hide();
        fileInput.fileupload('add', {files: files});

        e.preventDefault();
    }
});

jQuery('.js_toggleFileupload').fileupload({
    autoUpload: true,
    forceIframeTransport: true,
    progressInterval: 50,
    url: '/xhr',
    add: function (e, data) {

        console.debug(data); // this is where the data object has files

        var jqXHR = data.submit().done(function (e, data) { // this is where an empty file input is submitted
            //stuff happens here
        }
    }
});