File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

File Upload in Servlet failed for file size 2GB.

Sac Sha
Greenhorn

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
Marshal

Joined: Mar 22, 2005
Posts: 41601
    
  55
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.


Ping & DNS - my free Android networking tools app
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="http://tjws.sf.net" target="_blank" rel="nofollow">Get J2EE servlet container under 150Kbytes here</a><br />Love your iPod and want it anywhere?<a href="http://mediachest.sf.net" target="_blank" rel="nofollow">Check it here.</a><br /><a href="http://7bee.j2ee.us/book/Generics%20in%20JDK%201.5.html" target="_blank" rel="nofollow">Curious about generic in Java?</a><br /><a href="http://7bee.j2ee.us/bee/index-bee.html" target="_blank" rel="nofollow">Hate ant? Use bee.</a><br /><a href="http://7bee.j2ee.us/addressbook/" target="_blank" rel="nofollow">Need contacts anywhere?</a><br /><a href="http://searchdir.sourceforge.net/" target="_blank" rel="nofollow">How to promote your business with a search engine</a>
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File Upload in Servlet failed for file size 2GB.