8 Replies Latest reply on Nov 6, 2009 7:32 AM by pkatta

    Getting File size during s:fileUpload

    pkatta

      Hi,
      I am using s:fileUpload tag for uploading the file.
      But i want to restrict the file size to perticular size.
      Please inform for the same.

        • 1. Re: Getting File size during s:fileUpload
          v.lukoyanov

          Add following tag to components.xml:


          <web:multipart-request max-upload-size="5242880" create-temp-files="true"/>



          --------------

          My seam website

          • 2. Re: Getting File size during s:fileUpload
            pkatta

            Hi,
            I am having multiple file upload.
            This will apply for single filesize or for all the upload file sizes?

            • 3. Re: Getting File size during s:fileUpload
              v.lukoyanov

              That is maximum upload size for one single upload.


              --------------

              My seam website

              • 4. Re: Getting File size during s:fileUpload
                cash1981

                Vasilii L. wrote on Nov 03, 2009 16:02:


                Add following tag to components.xml:

                <web:multipart-request max-upload-size="5242880" create-temp-files="true"/>



                --------------

                My seam website


                Does this mean that the file is not held in memory?

                • 5. Re: Getting File size during s:fileUpload
                  cash1981

                  Vasilii L. wrote on Nov 03, 2009 16:02:


                  Add following tag to components.xml:

                  <web:multipart-request max-upload-size="5242880" create-temp-files="true"/>



                  --------------

                  My seam website


                  Also adding this to components.xml got me this exception:




                  java.lang.RuntimeException: Could not create Component: org.jboss.seam.web.multipartRequest
                  
                  Caused by: java.lang.IllegalArgumentException: component class is an interface: org.jboss.seam.web.multipartRequest
                  
                  


                  Are you sure you didn't include some other code in components.xml?


                  • 6. Re: Getting File size during s:fileUpload
                    cash1981

                    Vasilii L. wrote on Nov 05, 2009 12:38:


                    That is maximum upload size for one single upload.

                    --------------

                    My seam website


                    I don't think this is an exact science, because it will check the header Content-Length, and the content header length is not necessary the same as the filesize?


                    As shown from a snippet of MultipartRequestImpl it checks the Content-Length


                     public MultipartRequestImpl(HttpServletRequest request, boolean createTempFiles,
                    
                                int maxRequestSize)
                    
                       {
                    
                          super(request);
                    
                          this.request = request;
                    
                          this.createTempFiles = createTempFiles;
                    
                          
                    
                          String contentLength = request.getHeader("Content-Length");
                    
                          if (contentLength != null && maxRequestSize > 0 && 
                    
                                   Integer.parseInt(contentLength) > maxRequestSize)
                    
                          {
                    
                             throw new FileUploadException("Multipart request is larger than allowed size");
                    
                          }
                    
                       }



                    • 7. Re: Getting File size during s:fileUpload
                      cash1981

                      I had to inject the component directly with values from components.xml. The web filter didn't work for me:




                      <component class="org.jboss.seam.web.MultipartFilter">
                                <property name="createTempFiles">true</property>
                                <property name="maxRequestSize">104857600</property>
                           </component>



                      • 8. Re: Getting File size during s:fileUpload
                        pkatta
                        Hi,
                        for this error u havet to put enctype="multipart/form-data" for the 'Form' Tag.