blueimp/jQuery-File-Upload — Issue #993: Returning false in implemented send callback returns error in console.
Author: ariestav
Created: 2012-02-06 21:10:02+00:00
State: open

Hi There,

In my application I am trying to cancel some file uploads within a queue. The need is to cancel subsequent uploads if a threshold of successful uploads has been met.

So, I've implemented the following callbacks like so:

```

var _initObj; //contains the threshold maximum amount of files to be uploaded
var _uploadCount = 0;

$('#fileupload').bind('fileuploadstop', confirmUploadsDone);
$('#fileupload').bind('fileuploaddone', confirmUploadDone);
$('#fileupload').bind('fileuploadsend', confirmSend);

function confirmUploadsDone()
{
_uploadCount = 0;
}

function confirmUploadDone()
{
_uploadCount++;
}

function confirmSend(e, data)
{

console.log("Uploaded " + _uploadCount + " files.");
if (_uploadCount >= _initObj.tmplData.src_count) {
return false;
}
}
```
This works to cancel uploads after the threshold of successful uploads is met, but then, I get an error within Chrome's console:

```
Uncaught TypeError: Function.prototype.apply: Arguments list has wrong type
```

What's strange is that if I implement the send callback without an if statement, the TypeError is now thrown by the browser. For example, this works to cancel ALL uploads in the queue:

```
function confirmSend(e, data)
{
return false;
}
```
Which is what is expected as per the documentation. Can anybody shed some light as to why the TypeError is occurring? I would expect the uploader to just cancel the remaining files in the upload queue.

Thanks for your time and help!