Validate Total File Size On Submit

5 posts, 1 answers
  1. William
    William avatar
    23 posts
    Member since:
    Jan 2012

    Posted 01 Feb 2012 Link to this post

    I am using the upload widget on ASP.Net when I submit the form.  Due to the file size limit allowed by the server I need a way to cancel the submit if the combined size of the files selected for upload as above a set limit.  Any help is appreciated.

    Wade
  2. Answer
    Dimo
    Admin
    Dimo avatar
    8333 posts

    Posted 02 Feb 2012 Link to this post

    Hello Wade,

    You can use the Upload's select event, iterate through all files in the e.files array and check the size property of each file (object).

    http://www.kendoui.com/documentation/ui-widgets/upload/events.aspx

    However, note that due to browser limitations, this will not work in Internet Explorer, as it simply does not report the file size.

    Regards,
    Dimo
    the Telerik team
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Kendo UI is VS 2017 Ready
  4. William
    William avatar
    23 posts
    Member since:
    Jan 2012

    Posted 03 Feb 2012 Link to this post

    Well, not what I wanted to hear, but it is what it is.  Thanks.

    Wade
  5. Einar
    Einar avatar
    19 posts
    Member since:
    Jul 2014

    Posted 05 Nov 2014 in reply to Dimo Link to this post

    Dimo,

    I want to enforce 5MB size across all files (previously selected and currently selected).

    1. I select a 3mb file. (e.files = 1 file)
    2. I then select a 1mb file (e.files = 1 file)
    3. I then select a 10mb file. (e.files = 1 file)

    Does the Upload widget api expose previously selected files with their sizes or should I store this information myself?

    For this to work I'd need file sizes of previously selected files so that I can add that sum to the file(s) I'm trying to select to see if it exceeds 5mb.

  6. Dimo
    Admin
    Dimo avatar
    8333 posts

    Posted 06 Nov 2014 Link to this post

    Hello Einar,

    This is possible. Here is how to do it:

    - go to http://demos.telerik.com/kendo-ui/upload/index

    - select some files 2-3 times, so that they appear as 2-3 items in the Upload file list

    - open the browser's Javascript console and execute:

    $("#files").data("kendoUpload").wrapper.find(".k-file").each(function(idx, element) {
       console.log($(element).data("fileNames"));
    });

    In the console, you will get 2-3 arrays of objects. Each object will have a size field.

    Regards,
    Dimo
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
Back to Top
Kendo UI is VS 2017 Ready