This is a migrated thread and some comments may be shown as answers.

Cancelling File and IE8 Event Issue

1 Answer 68 Views
AsyncUpload
This is a migrated thread and some comments may be shown as answers.
KO
Top achievements
Rank 1
KO asked on 04 Sep 2012, 11:15 PM
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:

<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();
                }
            }

1 Answer, 1 is accepted

Sort by
0
Peter Filipov
Telerik team
answered on 07 Sep 2012, 11:24 AM
Hello Kelson,

RadAsyncUpload control supports MaxFileSize property which limit the maximum upload size. Straight to the point it is not possible to cancel manually the upload based on the selected file size. OnClientFileUploading event gives you the ability to cancel the upload. The uploaded files with 0 byte size could be handled on the server in FileUploaded event handler.

Kind regards,
Peter Filipov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
AsyncUpload
Asked by
KO
Top achievements
Rank 1
Answers by
Peter Filipov
Telerik team
Share this question
or