So we will be implementing RadAsyncUpload in a few different areas in our site. However, I had a question about cancelling an upload and I also noticed what seems to be a severe issue in Internet Explorer 8:
1. What is the best way to cancel a row from uploading its file on the client? I noticed what seem to be some internal javascript errors that get thrown no matter if I use _cancelUpload() or _stopUpdating(). To try and be the most safe I decided to find the cancel element itself and trigger a click client side, but I noticed some javascript errors from this too so I wanted to ask if this is normal? Cancelling like this:
2. OnClientProgressUpdating does not seem to trigger in Internet Explorer 8. The page loads with no errors or anything indicating a problem but when I debug and try to upload a file with zero size the AsyncUpload_ProgressUpdating function shown below is never executed and the file is flagged as a green file to be uploaded on the client, which is not good for us:
<
telerik:RadAsyncUpload
ID
=
"AsyncUpload"
runat
=
"server"
TemporaryFolder
=
"~/Uploads"
CssClass
=
"ClientFileUpload"
MultipleFileSelection
=
"Automatic"
AutoAddFileInputs
=
"true"
EnableInlineProgress
=
"true"
ControlObjectsVisibility
=
"RemoveButtons"
OnClientFileSelected
=
"AsyncUpload_FileSelected"
OnClientAdded
=
"AsyncUpload_AddClientSelection"
OnClientFileUploadFailed
=
"AsyncUpload_UploadFailed"
OnClientProgressUpdating
=
"AsyncUpload_ProgressUpdating"
/>
1. What is the best way to cancel a row from uploading its file on the client? I noticed what seem to be some internal javascript errors that get thrown no matter if I use _cancelUpload() or _stopUpdating(). To try and be the most safe I decided to find the cancel element itself and trigger a click client side, but I noticed some javascript errors from this too so I wanted to ask if this is normal? Cancelling like this:
// TODO: Instead of deleting the file input which seems to prompt the control to just force-create another
// input, cancel the upload by using the cancel element provided by Telerik. - KO 8/31/2012
//sender.deleteFileInputAt(eventArgs.get_rowIndex());
var errorRow = eventArgs.get_row();
// get the row's remove element
var cancelElement = $(errorRow).children('input')[0];
cancelElement.click();
badFile = true;
2. OnClientProgressUpdating does not seem to trigger in Internet Explorer 8. The page loads with no errors or anything indicating a problem but when I debug and try to upload a file with zero size the AsyncUpload_ProgressUpdating function shown below is never executed and the file is flagged as a green file to be uploaded on the client, which is not good for us:
function AsyncUpload_UploadFailed(sender, eventArgs) {
var errorMessage = eventArgs.get_message();
var errorCode = parseInt(errorMessage.substring(errorMessage.indexOf(":") + 1).trim());
// 0 must be code for cancelled upload
if (errorCode == 0) {
var errorRow = eventArgs.get_row();
var fileName = $(errorRow).children('span')[0].innerText.trim();
var extension = fileName.substring(fileName.lastIndexOf("."));
NotificationsWcfService.AddWarning("The file {0} has an inappropriate extension ({1})",
[fileName, extension]);
eventArgs.set_handled(true);
}
}
function AsyncUpload_ProgressUpdating(sender, eventArgs) {
var fileSize = eventArgs.get_data().fileSize;
// If the file size is zero then stop the upload by triggering a click on the cancel object.
// This is the only way I have found to "stop" an upload.
// This still causes javascript errors but they are the same errors that get generated from a user
// cancel click so I will assume this is the most safe. - KO 8/31/2012
if (fileSize <= 0) {
var errorRow = eventArgs.get_row();
// get the row's remove element
var cancelElement = $(errorRow).children('input')[0];
cancelElement.click();
}
}