1

I am using jsp/servlet for file upload,

i am able to upload a file but want to limit the size of files that can be uploaded. Is there any way to check the size of file without uploading it.. (on server side)

jmj
  • 237,923
  • 42
  • 401
  • 438
Varun
  • 5,001
  • 12
  • 54
  • 85

2 Answers2

3

You can set setSizeThreshold using commons-fileupload

Note: *You can't determine the file size without streaming it up directly to server*

jmj
  • 237,923
  • 42
  • 401
  • 438
  • i guess this will upload the data on server and display only threshold size of data at the target path... isnt it? – Varun Jan 05 '11 at 11:22
  • you can't check size of file without uploading it, this is standard way of implementing what you needed – jmj Jan 05 '11 at 11:23
  • so should we just upload the file first and then say sorry your file is too big to upload...?? – Varun Jan 06 '11 at 17:12
3

Is there any way to check the size of file without uploading it.. (on server side)

No, the server has no way to access the client's file system.

Not even Client-Side JavaScript may access the file system, for security reasons, so the only way would be to run some signed software with special privileges on the client (Signed Java Applet etc.). This would however require the client to allow the software to run.

The answer that makes the most sense is hence org.life.java's answer to limit the upload size from the server.

Community
  • 1
  • 1
Sean Patrick Floyd
  • 292,901
  • 67
  • 465
  • 588