Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

commons-fileupload-1.2.1. 4 kB limit

807589Nov 12 2008 — edited Nov 12 2008
Hi everybody.

I am using apache commons-fileupload-1.2.1.jar to upload files (multipart data). I have copy/pasted the code from their example page:
[http://commons.apache.org/fileupload/streaming.html]

However, I have problems. When I open the inputStream to a file, and check for stream.available(), it always returns 3904 - 3916. And then I write that data down to a blob and from there save it to a file and the file is always 4 kB long.

I have checked the limits of my Apache Tomcat. It allows files up to 20 MB.

I have used this code to get the data:
            File tem = new File("/");
            FileItemFactory factory = new DiskFileItemFactory(10000000,tem);
            
            // Create a new file upload handler
            ServletFileUpload upload = new ServletFileUpload();
            // Parse the request
            // maximum size before a FileUploadException will be thrown
            upload.setSizeMax(10000000);
            upload.setFileSizeMax(10000000);
            upload = new ServletFileUpload(factory);

            // Parse the request
            FileItemIterator iter = upload.getItemIterator(request);
            while (iter.hasNext()) {
                FileItemStream item = iter.next();
                String name = item.getFieldName();
                InputStream stream = item.openStream();
                
                if (item.isFormField()) {
                     
                     // source to do with form fields    
                    
                } else {
                     
                    BufferedInputStream bis = new BufferedInputStream(stream, 1000000);
                    out.println("Stream has: " + stream.available());
                    // prints out 3904 - 3916, depends on the file
                    
                    byte[] temp = new byte[stream.available()];
                    int bytesRead = stream.read(temp );
                    

                    out.print("Number of bytes read: " +bytesRead + "<br>");
                    // prints out 3904 - 3916, depends on the file



                    
            
            
                }
            }
            
Any ideas what to add or where the 4 kB limit is?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 10 2008
Added on Nov 12 2008
4 comments
456 views