When files are added i want to start the upload process automatically. I called the start function at the end of FilesAdded but it doesn't start the upload.
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();
});
Here is my creation code
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"}
],
});
Adding up.start()
in your FilesAdded bind should start the upload when a file is added. I've gone down the route of calling my uploader like so (I had problems doing it the way you are trying to call it):
$(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!
});
}
}
});
});
"Make sure you bind it after the init since it binds default handlers."
So your code:
uploader.bind('FilesAdded', function(up, files) {...});
after your
uploader.init();
more information
For me it didn't work your version but did work :
FilesAdded: function(up, files) {
setTimeout(function () { up.start(); }, 100);
},
So set a timer after 100 ms to execute the start. I am using the jquery ui version while testing and got this error :
g("#" + l.id).position() is null
/js/plupload/js/jquery.ui.plupload/jquery.ui.plupload.js
I was also wanting same for me and found below way to do it.
A new way to automatically start file uploading after adding file is just need to set true to autostart
property like below
$("#uploader").plupload({
.....
autostart: true,
.....
});
Just trigger the Start Upload button by this way
FilesAdded: function(up, files) {
$('#fileupload_start').click();
},
This will upload the file without waiting for 100 ms.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With