File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes File Upload in Servlet failed for file size 2GB. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "File Upload in Servlet failed for file size 2GB." Watch "File Upload in Servlet failed for file size 2GB." New topic

File Upload in Servlet failed for file size 2GB.

Sac Sha

Joined: May 04, 2006
Posts: 1
I am doing file upload using JSP which is calling my Servlet at the backend. The Servlet is not able to upload file with size 2GB. When I looked at the httpRequest parameters in doPost method, I am getting negative value for contentLength (httpRequest.getContentLength()). Because of this negative value the issue is coming.

Any clues or suggestions on this?

Thanks in advance.
Satish SN
Ranch Hand

Joined: Apr 19, 2005
Posts: 70
Sac Sha,

there could be multiple reasons

1. did u get outofmemory exception during the upload process on the server side.

2. u did not mention which jar or application frame work ur using means are u using orielly upload jar or using the struts framework both have certain parameters need to be set for large files.

Satish SN<br />SCJP 1.4 & SCWCD 1.4
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
That method returns an "int", which -being 32 bit long- is negative for values over 2GB. I haven't thought this through, but I think this implies that the current version of the Servlet API can't handle requests that large.
dema rogatkin
Ranch Hand

Joined: Oct 09, 2002
Posts: 294
There is a simple work around. You servelt has to request content length and if it's negative or number format exception happened, then process it as http header.

Tough in space?, <a href="" target="_blank" rel="nofollow">Get J2EE servlet container under 150Kbytes here</a><br />Love your iPod and want it anywhere?<a href="" target="_blank" rel="nofollow">Check it here.</a><br /><a href="" target="_blank" rel="nofollow">Curious about generic in Java?</a><br /><a href="" target="_blank" rel="nofollow">Hate ant? Use bee.</a><br /><a href="" target="_blank" rel="nofollow">Need contacts anywhere?</a><br /><a href="" target="_blank" rel="nofollow">How to promote your business with a search engine</a>
I agree. Here's the link:
subject: File Upload in Servlet failed for file size 2GB.
It's not a secret anymore!