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
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:
functiongetFileInfoFromComplete(e) {
return $.map(e.getFiles(), function(file) {
var info = file.name;
// File size is not available in all browsersif (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:
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/.
This isn't working for me. getFileInfo() always returns an empty string. I'm not sure what I'm doing wrong, this seems like it should work. The goal is to send the filename to the method so a background import routine can be launched to process the specified filename.
functiongetFileInfo(e) {
var fileData = $.map(e.files, function (file) {
var info = file.name;
// File size is not available in all browsersif (file.size > 0) {
info += " (" + Math.ceil(file.size / 1024) + " KB)";
}
return info;
}).join(", ");
return fileData;
}
I've prepared a sample project that demonstrates the approach suggested above and everything seems to be working as expected. I hope it will help you to resolve the issue. Otherwise, could you try to replicate the issue in a sample project and send it to me, so I can review it and come up with a possible solution?