11 Replies Latest reply on Jun 24, 2015 1:16 AM by bhanugst2015

    rich:upload fileUploadListener not called for large files

    pradeepa.kadiyala

      I have a rich:upload segment in my code which was working fine until now. All of a sudden it started to behave weird. For small size files say upto 100KB, the file:uploadListener gets called when I click on the Choose File button and file gets uploaded. But somehow the same does not happen for files greater than 100KB. I have the following in my web.xml for file upload restriction:

      <context-param>
        <param-name>org.richfaces.fileUpload.maxRequestSize</param-name>
        <param-value>4000000</param-value>
      </context-param>
      
      

      Following is my xhtml code:

      <rich:fileUpload fileUploadListener="#{myBean.uploadFileData}" id="upload"  
        immediateUpload="true" render="@form" addLabel="Choose File">
        <a4j:ajax render="@form" execute="@form" event="uploadcomplete"/>
        </rich:fileUpload> 
      

       

      Message was edited by: Pradeepa Kadiyala

        • 1. Re: rich:upload fileUploadListener not called for large files
          michpetrov

          Are you getting any browser or server errors? What's your version of RichFaces?

          • 2. Re: rich:upload fileUploadListener not called for large files
            pradeepa.kadiyala

            Hi Michal!
            We are using richFaces 4.3 version and as we moved further with testing, we found that it was working properly on our local machines but failed to run on the UAT and production servers. We are using JBOSS EAP 6.2 server.
            Not getting any browser or server errors. It is just that for larger files than 100KB the event listener does not get called.

            • 3. Re: rich:upload fileUploadListener not called for large files
              michpetrov

              If the listener isn't called it would mean that there is no file to process, but if you can get it to work on one server then the problem is probably with server settings. Servers may have their own setting for file transfers but I wouldn't expect it to be that low (and you should still get an upload error if that was the case).

              • 4. Re: rich:upload fileUploadListener not called for large files
                bhanugst2015

                Hi Pradeep ,

                 

                    any error you are seeing in console . It may be due to Hardware support also some times .

                • 5. Re: rich:upload fileUploadListener not called for large files
                  pradeepa.kadiyala

                  Hi Bhanu,

                  No error in the console. For files less than 100KB everything works fine. For files larger than 100KB the listener does not get fired and so not able to upload the file. Is it possible to restrict the file uplaod capacity from the server or the network?

                   

                  FYI I am Pradeepa* not Pradeep

                  • 6. Re: rich:upload fileUploadListener not called for large files
                    bhanugst2015

                    Pradeep ,

                     

                                The i guess its a Hardware related one / internal image file settings . Yes you can restrict the file size . Your compression method will be some thing like this :

                     

                    public byte[] resizeImageAsJPG(byte[] pImageData, int pMaxWidth) throws IOException {
                       // Create an ImageIcon from the image data
                       ImageIcon imageIcon = new ImageIcon(pImageData);
                       int width = imageIcon.getIconWidth();
                       int height = imageIcon.getIconHeight();
                       // If the image is larger than the max width, we need to resize it
                       if (pMaxWidth > 0 && width > pMaxWidth) {
                       // Determine the shrink ratio
                       double ratio = (double) pMaxWidth / imageIcon.getIconWidth();
                       height = (int) (imageIcon.getIconHeight() * ratio);
                       width = pMaxWidth;
                       }
                       if(width < 0 || height < 0) {
                       return new byte[0];
                       }
                       // Create a new empty image buffer to "draw" the resized image into
                       BufferedImage bufferedResizedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
                       // Create a Graphics object to do the "drawing"
                       Graphics2D g2d = bufferedResizedImage.createGraphics();
                       g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
                       // Draw the resized image
                       g2d.drawImage(imageIcon.getImage(), 0, 0, width, height, null);
                       g2d.dispose();
                       // Now our buffered image is ready
                       // Encode it as a JPEG
                       ByteArrayOutputStream encoderOutputStream = new ByteArrayOutputStream();
                       JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(encoderOutputStream);
                       encoder.encode(bufferedResizedImage);
                       byte[] resizedImageByteArray = encoderOutputStream.toByteArray();
                       return resizedImageByteArray;
                    }

                    Hope this may help you .

                    • 7. Re: rich:upload fileUploadListener not called for large files
                      pradeepa.kadiyala

                      Bhanu ,

                       

                      We are having the upload as an identity or address proof and we support JPG pdf,png,all such formats. I am afraid but we cannot use the above method suggested by you.

                      As you said might be some internal issues, can u specify if what settings we might have changed.
                      Also we use apache tomcat 7.0.47 as the web server and our application is deployed on JBOSS EAP 6.2. On our local we have only the JBOSS server.

                      • 8. Re: rich:upload fileUploadListener not called for large files
                        michpetrov

                        If the problem is with the file handling listener not being called, I'm not sure how an image resizing method would help when you cannot use it.

                         

                        pradeepa.kadiyala, check your server configuration for "max-post-size", but if that's not it I don't know where the problem is.

                        • 9. Re: rich:upload fileUploadListener not called for large files
                          bhanugst2015

                          Hi Pradeepa ,

                           

                                     we will be having 3 things here :

                          1. createTempfile

                          2. maxRequestSize

                          3. <web:multipart-filter disabled="true" /> in components.xml

                           

                          Apart from this there is nothing which may go wrong according my view . Even if it is an address proof we can compress the size of the image by setting the default resolution . We had tried with ID Proof in our applications and it is working perfectly .maximum image width we had taken is 800 .

                          • 10. Re: rich:upload fileUploadListener not called for large files
                            pradeepa.kadiyala

                            hi Bhanu,

                             

                            The problem is we have the requirement to support all sorts of file types, so it isnt necessary that we have an image. It can also be a PDF, DOC etc.

                            As per your suggestions checked for all 3..
                            found 2 of them in our web.xml.

                             

                            <context-param>

                              <param-name>org.richfaces.fileUpload.createTempFiles</param-name>

                              <param-value>false</param-value>

                              </context-param>

                             

                             

                              <context-param>

                              <param-name>org.richfaces.fileUpload.maxRequestSize</param-name>

                              <param-value>52800000</param-value>

                              </context-param>

                             

                            and the 3rd in components.xml

                            <web:multipart-filter disabled="true" />

                             

                            still unable to fix the issue

                            • 11. Re: rich:upload fileUploadListener not called for large files
                              bhanugst2015

                              Hi Pradeepa ,

                               

                                         Iam figuring out from my end will let you know . Try this link . i think this may help :

                               

                              Big file with <rich:fileUpload>