How to block RadAsyncUpload control from uploading empty/0KB files

1 Answer 244 Views
AsyncUpload
Jeff
Top achievements
Rank 2
Iron
Iron
Veteran
Jeff asked on 03 Mar 2022, 08:18 PM

When a user drags and drops a file from a third-party file management application we use into our own ticketing system the file is empty (0 KB in size).  This is an issue with their application for which I'm building a workaround.

The RadAsyncUpload control allows this file to be added to the upload files collection, and uploaded to the site.  An error is received when attempting to access this file, as one would expect.

Using the OnClientFileDropped event, I can read the file size property.  If it's 0, add it to an array that is then read in the OnClientFileUploading event.  If the current filename exists in this array, I cancel the upload. 

My preference would be to handle this all within the OnClientFileUploading event.  As of yet, I've been unable to read the file size within this event, and I'm presuming it is not available there.

Again, assuming I cannot get the file size property in this event, is there an event that occurs after the args.set_cancel(true) method is triggered, where I can remove these canceled uploads from the displayed list?

 

1 Answer, 1 is accepted

Sort by
0
Doncho
Telerik team
answered on 07 Mar 2022, 02:13 PM

Hi Jeff,

One approach you can try is to use the OnClientProgressUpdating to store and keep track of the file size of each uploaded file. Then in the OnClientFileUploaded event, you can remove any files that are beyond the allowed file size (below a predefined minimum). A similar approach is demonstrated in the following code library sample:

The sample demonstrates limiting the max allowed size, but you can modify it to limit the minimal size.

I hope you will find this helpful.

Please let me know if any questions come up.

Kind regards,
Doncho
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Jeff
Top achievements
Rank 2
Iron
Iron
Veteran
commented on 08 Mar 2022, 12:45 PM

Doncho,

Thank you for the suggested approach.  The title of this question is now misleading, as I've come up with a way to block these files.  The issue now is purely aesthetic because the files are blocked, but they still appear in the list of files. 

Our third-party application duplicates each file when you drag and drop, and I've been able to block them.  But what I'd like to do now is remove the duplicate from the shown list (screenshot attached here).  Is this possible without re-writing my processes in the manner you've suggested?

As you can see, the red dot in the front the file name shows they were not, and will not be uploaded.  I just don't want it to appear twice, as it is here.

Once you cancel an upload, can it be removed from the list?

Jeff
Top achievements
Rank 2
Iron
Iron
Veteran
commented on 08 Mar 2022, 03:43 PM

I just came up with a "hack" way to do this.  In the OnClientFileSelected event, if the current file exists in the filesToCancel array built in the OnClientDropped event, I hide the row.  This gives me the result I need.  But I think it's a little "hacky".  

Is there a better way to remove this row at this point?


function onClientFileSelected(sender, args) {
     let row = args.get_row();
     if (filesToCancel.includes(args.get_fileName())) {
         row.hidden = true;
     };
 };

Peter Milchev
Telerik team
commented on 11 Mar 2022, 12:13 PM

Hi Jeff, you can try the deleteFileInputAt() client-side method and remove the file based on the row's index:

Tags
AsyncUpload
Asked by
Jeff
Top achievements
Rank 2
Iron
Iron
Veteran
Answers by
Doncho
Telerik team
Share this question
or