I am using the igUpload jquery upload sample (2011.2\jQuery\Samples\Samples\igUpload\Display\ClientSideEvents\HTML\ClientSideEvents.html) and have tailored this to cancel the fileUploading event as follows (the only change to the sample code is marked in bold):
fileUploading: function (e, args) { var message = "<div class='event-fired'>fileUploading " + "event fired, with file arguments:" + "</div>" + "<div class='event-args'>" + "File ID: " + args.fileId + "<br />" + "File Path: " + args.filePath + "<br />" + "File Status: " + args.fileStatus + "<br />" + "TotalSize: " + args.totalSize + "<br />" + "Uploaded Bytes: " + args.uploadedBytes + "</div>"; showEvent(message); return false; },
The documentation (http://help.infragistics.com/NetAdvantage/jQuery/Current/CLR4.0) states that this should cancel the event. However, with this change, I still witness the fileSelected event being fired.
I would expect (and desire) this cancellation to stop uploading the file, reset the progress bar and not to call the fileUploaded event handler.
I suspect this error is not down to usage as cancellation of the fileSelecting event works as expected.
Can you confirm how I attain the behaviour I require?
Hi AlistairWood,
About firing event fileUploading there is very important note. FileUploading event is fired when the client script has been made request to the server to get status about file upload progress(after the file has started uploading). And when the server responses to the client then it is fired this event. But meanwhile it is possible the file to be uploaded and then even if you cancel upload it won't have effect. So you should check status(in event arguments) whether file is uploaded. And that's why when the file is uploaded(even if you cancel fileUploading event) fileUploaded event will be fired. This is not an error of fileUploading event.You can try just with huge files to see that you can cancel event and see it is working properly.
Also fileSelected event is fired before fileUploading event.(you should select file before you upload it).
Thanks,
Miro Hristov
Thanks for the confirmation that I cannot rely on this event for cancelling the upload.
Is there a reliable way to provide additional validation in the file upload control that causes the progress bar to be reset?My original route was to perform validation in the fileUploading event handler which, on failure, stops uploading the file, resets the progress bar and ensures no call to the fileUploaded event handler.
What exactly validation you want to do? I mean if you are using client validation(javascript) you can handle fileSelected event and to cancel file uploading - as call public function cancelUpload. Can you clarify and tell us more details?
Let me know if you need additional assistance with this question.