2 Replies Latest reply on Oct 17, 2011 7:23 AM by derkd

    rich:fileUpload getFileName() and getMime() resolves to null

    derkd

      Hi all,

       

      I'm using the rich:fileUpload but in the event the getMime and the getFileName resolve to null. I also see this hapening in the example in the showcase. Is this a bug? I have copied the example from the showcase and I'm seeing the uploaded picture on my screen with the size in bytes.

      I'm using tomcat 6, JSF 2 and richfaces 4.

       

       

        public void hoofdFotoListener(FileUploadEvent event) throws Exception {

          log.debug("entered hoofdlistener");

              UploadedFile item = event.getUploadedFile();

              UploadedImage file = new UploadedImage();

              file.setLength(item.getData().length);

              file.setName(item.getName());

              log.debug("mime type " + file.getMime());

              file.setData(item.getData());

              getUploadedHoofdFotos().add(file);

          }

       

      this is a snippet of my web.xml:

       

        <context-param>

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

        <param-value>true</param-value>

        </context-param>

        <context-param>

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

        <param-value>100000</param-value>

        </context-param>

       

      Am I doing something wrong?

        • 1. Re: rich:fileUpload getFileName() and getMime() resolves to null
          derkd

          I got it partly working. I also use PrettyFaces and that's where probably the problem is.

           

          When I replace this:

           

          <filter>

            <filter-name>Pretty Filter</filter-name>

                              <filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>

            </filter>

           

            <filter-mapping>

            <filter-name>Pretty Filter</filter-name>

            <url-pattern>/*</url-pattern>

            <dispatcher>FORWARD</dispatcher>

            <dispatcher>REQUEST</dispatcher>

            <dispatcher>ERROR</dispatcher>

            </filter-mapping>

           

          with this:

           

          <filter>

            <filter-name>Pretty Filter</filter-name>

                              <filter-class>com.ocpsoft.pretty.PrettyFilter</filter-class>

            <async-supported>true</async-supported>

            </filter>

           

            <filter-mapping>

            <filter-name>Pretty Filter</filter-name>

            <url-pattern>/*</url-pattern>

            <dispatcher>FORWARD</dispatcher>

            <dispatcher>REQUEST</dispatcher>

            <dispatcher>ERROR</dispatcher>

            <dispatcher>ASYNCHRONOUS</dispatcher>

            </filter-mapping>

           

          Now I get the filename back but the getMime() still resolves to null...

          • 2. Re: rich:fileUpload getFileName() and getMime() resolves to null
            derkd

            Well I'm a bit further.

            The mime type is set when the setName() of the UploadedImage is called. So you have to make sure that the setName has been called before calling the getMime(). Next there is a bug in the setName() of the UploadedImage in the showcase. I added a comment to fix this (https://issues.jboss.org/browse/RF-11218)

             

            public void setName(String name) {

                    int extDot = name.lastIndexOf('.');

                    if (extDot > 0) {

                        String extension = name.substring(extDot + 1);

                        if ("bmp".equals(extension)) {

                            mime = "image/bmp";

                        } else if ("jpg".equals(extension)) {

                            mime = "image/jpeg";

                        } else if ("gif".equals(extension)) {

                            mime = "image/gif";

                        } else if ("png".equals(extension)) {

                            mime = "image/png";

                        } else {

                            mime = "image/unknown";

                        }

                    }

                }

             

            the attribuut name isn't set!

            this must be added

             

            this.name = name;

             

            Regards,

             

            Derk