6 Replies Latest reply on Jun 27, 2007 8:57 AM by tazman

    Restrict file upload size individually

    codest

      Hi there,

      is there a possibility to check the size of a file when uploading with s:fileUpload? I know about the configuration directive maxRequestSize, but I have different limits in an application, depending on which files I want to upload (e.g. a foto vs. a pdf document).

      So how can I check the size of an uploaded file to reject it if necessary?

      Thanks in advance,
      regards,
      Jörg

        • 1. Re: Restrict file upload size individually
          pmuir

           

          <s:fileUpload ... fileSize="#{foo.fixeSize}" />


          Then check the fileSize in your action method.

          • 2. Re: Restrict file upload size individually
            codest

            Thank you very much, Pete.

            Is this missing in the docs? I can't find it there (I'm using version 1.2.1.GA).

            Regards,
            Jörg

            • 3. Re: Restrict file upload size individually
              pmuir

              Yes it is, I'll update them :)

              • 4. Re: Restrict file upload size individually
                tazman

                Is there a way to make s:fileUpload throw FileUploadException on a per case basis before reading the whole stream? I don't want uploading a file happens if I'll discard it anyway.

                • 5. Re: Restrict file upload size individually
                  pmuir

                  Well http will post the file data to the server before invoking any JSF stuff - so its uploaded whatever. If you point data at a InputStream, then fileUpload doesn't read in the stream, you do in your backing bean.

                  • 6. Re: Restrict file upload size individually
                    tazman

                    If I have this in my components.xml

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


                    then the filter just checks the Content-Length of the HTTP request and throws the exception before reading the HTTP content if the length is bigger that the maxRequestSize. So the file is not really uploaded to the server and doesn't consume any memory resources.

                    Whereas, with

                    <s:fileUpload ... fileSize="#{foo.fixedSize}" />


                    the filter reads the content and gives my backing bean the control to decide. I'd like to have the maxRequestSize behavior in this case as well. Is it doable? Is my understanding correct?

                    tazman