gpt4 book ai didi

javascript - 带有拖放功能的 jQuery fileupload 提交空文件输入

转载 作者:行者123 更新时间:2023-12-01 01:45:41 26 4
gpt4 key购买 nike

我正在使用 jQuery fileupload 插件,该插件在通过单击文件输入并通过浏览器对话框进行选择来上传文件时效果非常好。

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

------WebKitFormBoundaryCA4VuYwsPr7h4ItR
Content-Disposition: form-data; name="attachment"; filename=""
Content-Type: application/octet-stream

虽然 fileupload 的 add 回调中的数据对象在调用 data.submit() 之前确实有一个文件

files: Array[1]
0: File
lastModifiedDate: Tue Mar 18 2014 13:29:07 GMT+0100 (CET)
name: "17_1395143728_0.png"
size: 13542
tempID: 1
type: "image/png"
webkitRelativePath: ""
__proto__: File
length: 1

有人知道为什么会发生这种情况吗?

编辑:代码:

$(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 - 带有拖放功能的 jQuery fileupload 提交空文件输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24930386/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com