gpt4 book ai didi

javascript - Plupload 添加文件时自动开始上传

转载 作者:行者123 更新时间:2023-12-03 12:23:14 26 4
gpt4 key购买 nike

添加文件后,我想自动开始上传过程。我在 FilesAdded 的末尾调用了 start 函数,但它没有开始上传。

uploader.bind('FilesAdded', function(up, files) {
var str = "";
for (var i in files) {
str += '<div id="' + files[i].id + '">' + files[i].name + ' (' + plupload.formatSize(files[i].size) + ') <b></b></div>';
}
$('#filelist').html(str);
up.refresh();
up.start();
});

这是我的创建代码
var uploader = new plupload.Uploader({
runtimes: 'html5,flash,silverlight',
autostart : true,
url: '<%= images_path %>',
max_file_size: '10mb',
multipart: true,
browse_button: "pickfiles",
container: "the-uploader",
drop_element : "drop-area",
multipart_params: {
'_http_accept': 'application/javascript',
'<%=request_forgery_protection_token%>': '<%=form_authenticity_token%>',
'<%=request.session_options[:key]%>': '<%=request.session_options[:id]%>'
},
filters: [
{title: "Images", extensions: "avi,jpg,jpeg,png,zip"}
],
});

最佳答案

添加 up.start()在您的 FilesAdded 绑定(bind)中应该在添加文件时开始上传。我已经像这样调用我的 uploader (我在你尝试调用它的方式时遇到了问题):

$(function() {
// Setup html5 version
$("#html5_uploader").pluploadQueue({
// General settings
runtimes : 'html5',
url : 'upload.php',
max_file_size : '10mb',
chunk_size : '1mb',
unique_names : true,
dragdrop : true,
multiple_queues : false,
multi_selection : false,
max_file_count : 1,

// Specify what files to browse for
filters : [
{title : "Text files", extensions : "txt"}
],

init : {
FilesAdded: function(up, files) {
up.start();
},
UploadComplete: function(up, files) {
$.each(files, function(i, file) {
// Do stuff with the file. There will only be one file as it uploaded straight after adding!
});
}
}
});
});

关于javascript - Plupload 添加文件时自动开始上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8137229/

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