[CLOSED] FileFileUploadField validate file size before uploading it

  1. #1

    [CLOSED] FileFileUploadField validate file size before uploading it

    Hello,
    I have a FileUploadField control, I want to validate the size of the file to be uploaded on selecting it which means on first browsing and selecting the file directly and before waiting the FileUploadField control to upload it or pressing a submit button validate its size.
    is there anyway to validate client side?

    Thank you
    Last edited by fabricio.murta; Nov 11, 2016 at 4:50 PM. Reason: no user feedback for 7+ days
  2. #2
    Hello!

    Yes, you can just use HTML5 DOM's file input field's size property to get the size of the selected file.

    You get the DOM object of the input file from a FileUploadField component via its FileInputElement property.

    I hope this helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Hello,

    Please take look to the piece of code, I used "fileInputEl" property and i got the dom of the file upload field but the size is always 1.

     function test()
            {
                
                console.log(App.FileUpload.fileInputEl.dom.size);  //always 1
            }


    <ext:FileUploadField ID="FileUpload" runat="server" Width="500" Icon="Attach"  FieldLabel="Browse"    >
    
                                        <Listeners>
                                            <Change Handler="test();" />
                                        </Listeners>
                                    </ext:FileUploadField>
    is there any suggestions?
  4. #4
    Hello @geovision!

    Here's the literature on the input element by MDN: <input>

    On this page, scroll down to where they explain the "size" attribute. It is just the size of the control. Not what we want.
    Scroll further down, and you'll see a Notes section talking about files handling, and redirecting you to Using files from web applications.

    On this new page, you'll see how it does access the files in an <input type="file" /> element. It is a files array. Then each entry of this array can contain one of the many possible selected files at once. Each file is a File object.

    Now the problem is that in the MDN documentation for the File Object there's no mention for a size field at a first look. But if I expand this on Internet Explorer 11 at least, after selecting a file in a text field I can get it with:

    App.FileUpload.fileInputEl.dom.files[0].size
    But according to the following stackoverflow question, this is something reasonably recent, and possibly not supported in all browsers: JavaScript file upload size validation.

    So, that's the way to use it, but I'm not really sure which browsers will support it. This is not an Ext.NET nor ExtJS feature at all, and there's no support client side for both ExtJS and Ext.NET to get the file size (Ext.NET provides facilities to get the file size server side though).

    I hope this helps clarifying the usage and limitations of client-side file size querying!
    Fabrício Murta
    Developer & Support Expert
  5. #5
    Hello @Geovision!

    We didn't hear back from you for some time now. Do you still need help with this issue?
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. Uploading file using MVC
    By ingbabic in forum 2.x Help
    Replies: 1
    Last Post: Jan 27, 2015, 9:07 AM
  2. Uploading file
    By massman07 in forum 2.x Help
    Replies: 3
    Last Post: Aug 12, 2014, 8:45 PM
  3. [CLOSED] How to identify upload file size before uploading in IE?
    By rnachman in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jun 29, 2012, 5:54 PM
  4. Replies: 2
    Last Post: Jan 17, 2012, 8:58 AM
  5. [CLOSED] Validate file size using FileUpload in client side
    By Pablo_Azevedo in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Oct 28, 2011, 4:12 PM

Posting Permissions