Solved

Get file size before upload begins

Posted on 2007-04-09
5
2,905 Views
Last Modified: 2013-11-21
Hello Friends,
I want to throw an error immediately if user is trying to upload a file of size greater than the specified limit. We are checking content-Length for this.

If Im not mistaken, for large files the issue is because of the behaviours of HTML and Java: Once the user hits on upload button, the file is included in the request body as the enctype is multipart/form-data. If the connection is slower [this application can be used over internet from user being anywhere in the world] the time taken for a file >10 MBs is considerable.

By the time the whole request is prepared and sent to the server, a lot of time elapses. Then the method you have specified can be called on the fileItem.

If the user is trying to upload a file way above the limit, like of 50MB or 100MB, then the time taken to reach till the point error gets thrown increases.

As of now we are experiencing delays in giving the size limit error message to user like the following- 10MB file ~ 10minutes. 33 MB file ~ 30 minutes and so on.

What can we do for improving this? Or is there any way to get the file size before even the upload begins?

rahulak
0
Comment
Question by:rahulak
5 Comments
 
LVL 11

Accepted Solution

by:
Manish earned 43 total points
ID: 18897001
0
 
LVL 7

Assisted Solution

by:Chandan_Gowda
Chandan_Gowda earned 41 total points
ID: 18936768
0
 
LVL 51

Assisted Solution

by:ahoffmann
ahoffmann earned 41 total points
ID: 19041967
most servers start the application (wether in Java or any other language) right *after* it completed to read the hole request.
Hence it's a more or less useless attempt to check the size in the application for performance/bandwidth issues, obviously.
If your server passes the connection to your application right away, then you can read the content-Length header yourself and decide what to do.But keep in mind that ther must not be such a header if the client sends the data using Connection:close. In that case you have to read data 'til your limit.
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question