Reputation: 25542
I am working on an application that uses the plupload library for file uploading. I can't seem to get the file uploading working because there is some kind of error but I can't get this error to alert or log.
Has anyone been able to do this?
Here is my current code:
uploader.bind('Error', function(error){
console.log(error);
});
Thanks in advance for any help!
Upvotes: 2
Views: 11000
Reputation: 190
I was also searching for error handling mechanism provided by Plupload widget, none of the answers were working. So here is the working one (per version 2.1.2):
$(FileUpload.container).pluploadQueue({
// General settings
runtimes: 'html5,flash,silverlight,html4',
url: "saveFiles",
chunk_size: '1mb',
rename: true,
dragdrop: true,
multipart : true,
unique_names : true,
filters: {
// Maximum file size
max_file_size: '16mb',
// Specify what files to browse for
mime_types: [
{title: "XML files", extensions: "xml"}
]
},
// Flash settings
flash_swf_url: '/plupload/js/Moxie.swf',
// Silverlight settings
silverlight_xap_url: '/plupload/js/Moxie.xap',
init : {
Error: function(up, args) {
// Called when error occurs
Daedalus.localMessage("XML file is not valid!");
}
}
});
The "init" object has more supported events, refer to http://www.plupload.com/examples/events
Upvotes: 0
Reputation: 8745
Binding to the error event requires two params:
var uploader = $("#uploader").pluploadQueue();
uploader.bind('Error', function(uploader, e) {
console.error(e);
});
Upvotes: 2
Reputation: 3286
Another late answer. If I were you i would start with changins stuff like:
$('form').submit(function(e) {
into something like:
$('form').bind('submit', function(e) {
and stuff like that:
$('form').submit();
into:
$('form').trigger('submit');
Also I would move all these binds out of $(form).submit.
uploader.bind('UploadProgress', function() {
if (uploader.total.uploaded == uploader.files.length)
$('form').submit();
});
Just for sake of simiplicity and debugability.
Unfortunately still have no idea what's wrong with your script. Maybe you are missing:
uploader.init();
Maybe:
if (uploader.total.uploaded == 0) {
is not triggering.
Nevertheless some console.log after each line should help. :)
Upvotes: 1
Reputation: 9857
So I know this is probably way too late, but I just started with plupload and was in a helpful mood...
The reason the console never logs anything is because the binding that you are doing only occurs when all uploads have been completed.
You need to put this code before the $('form').submit()
line:
uploader = $('#plupload').pluploadQueue();
uploader.bind('Error', function(error){
console.log(error);
});
Upvotes: 2
Reputation: 25542
Here is my entire code base for trying to get this to work
$('#plupload').pluploadQueue({
runtimes : 'flash, html5',
url : '/admin/upload/do_upload/',
filters : [
{title : "Image Files", extensions : "jpg,gif,png"}
],
flash_swf_url : "/js/admin/plupload/plupload.flash.swf"
});
$('form').submit(function(e) {
alert('EHY');
var uploader = $('#plupload').pluploadQueue();
// Validate number of uploaded files
if (uploader.total.uploaded == 0) {
// Files in queue upload them first
if (uploader.files.length > 0) {
// When all files are uploaded submit form
uploader.bind('UploadProgress', function() {
if (uploader.total.uploaded == uploader.files.length)
$('form').submit();
});
uploader.start();
uploader.bind('Error', function(error){
console.log(error);
});
} else
alert('You must at least upload one file.');
e.preventDefault();
}
});
Upvotes: 0