Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By Tolls

Thread: restrict file size before upload

  1. #1
    javaforums187 is offline Member
    Join Date
    Jun 2011
    Posts
    3
    Rep Power
    0

    Default restrict file size before upload

    Hello all,

    In JSP / HTML, I want to restrict the size of file being uploaded. I've <input type="file" name="myfile"/>

    If the size of file more than a specific size say 5MB, i want to give mesage to the user. I don't want to wait till the file gets uploaded to server and then validate the file size. I need client side validation. Can it be done using scripting language or any other way?

    I need a solution for this in Internet Explorer. There is already a solution I got using ActiveX control:
    var myFSO = new ActiveXObject("Scripting.FileSystemObject");
    var filepath = document.getElementById('myfile').value;
    var thefile = myFSO.getFile(filepath);
    var sizeInBytes = thefile.size;


    But ActiveX controls are not allowed in our application. Is there any alternative way for this?

    PLease suggest the possible ways.. Thanks in advance!!

    ----
    Poli reddy

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,854
    Rep Power
    19

    Default

    That would be javascript and, as far as I'm aware, security would normally prevent javascript from pulling such information from the file system.
    Though, since it's Javascript, you'd probably get more accurate answers from a Javascript forum.

  3. #3
    javaforums187 is offline Member
    Join Date
    Jun 2011
    Posts
    3
    Rep Power
    0

    Default

    Thanks Tolls. I checked in javascript forums.. there is no solution using javascript other than ActiveX control. Is it possible using Applet??

  4. #4
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,854
    Rep Power
    19

    Default

    The Applet would need to be signed to allow access to the client machine so it can find the file size.
    javaforums187 likes this.

  5. #5
    javaforums187 is offline Member
    Join Date
    Jun 2011
    Posts
    3
    Rep Power
    0

    Default

    Thanks Tolls.. I've used applets and it worked.

    jUpload soved this issue:
    File upload applet - HTTP/FTP upload - JFileUpload => download link
    JUpload - File Upload Applet (HowTo - customize it) => documentation
    *JFileUpload - HTTP upload parameters => config params

    maxsize- This parameter identify the maximum size of the uploaded file. It prevents the user to upload too big files.

    thanks to the forum too..!!

Similar Threads

  1. Replies: 6
    Last Post: 05-29-2011, 12:14 PM
  2. File upload
    By bekir in forum Java Servlet
    Replies: 2
    Last Post: 04-08-2011, 03:17 PM
  3. how to restrict the size of the window in swt
    By chakribobby in forum SWT / JFace
    Replies: 2
    Last Post: 06-09-2010, 03:31 PM
  4. :large file upload to server(chunk upload)
    By tommy_725 in forum Networking
    Replies: 0
    Last Post: 10-16-2009, 12:21 AM
  5. File Upload
    By ShoeNinja in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 11-09-2007, 10:09 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •