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

Get file list in onComplete event?

1 Answer 25 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 1
Joe asked on 11 Mar 2021, 07:31 PM

Several of the examples use a getFileInfo(e) routine to pull out the file list in the upload control.  This works well in events like onSelect().

Is it possible to retrieve the filename or list of files in the client side onComplete(e) event?

1 Answer, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 16 Mar 2021, 04:09 PM

Hello Joe,

You can get the file list in the "Complete" event's handler, but you should use a slightly different approach.

Instead of the getFileInfo function used by some events (e.g., "Select") in the demo, create another function:

function getFileInfoFromComplete(e) {
  return $.map(e.getFiles(), function(file) {
    var info = file.name;

    // File size is not available in all browsers
    if (file.size > 0) {
      info  += " (" + Math.ceil(file.size / 1024) + " KB)";
    }
    return info;
  }).join(", ");
}

Note that it uses the getFiles() API method of the Upload.

When you call this function, instead of passing the event data (e), you will pass a reference to the Upload (e.sender), as demonstrated below:

function onComplete(e) {
    console.log("Complete :: " + getFileInfoFromComplete(e.sender));
}

This will allow you to use the getFiles method mentioned above.

Give this a try and let us know the results.

Regards,
Ivan Danchev
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Upload
Asked by
Joe
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Share this question
or