9 Replies Latest reply on Jun 14, 2007 5:22 PM by nhpvti

    Do file upload component support jpeg and png only?

    nhpvti

      We'd need GIF images upload functionality.

      Here
      http://www.jboss.org/index.html?module=bb&op=viewtopic&t=100433&postdays=0&postorder=asc&start=0
      I found a statement that

      seamspace only supports jpeg and png


      Question: does this mean that the file upload component does not support GIF format?

      Another problem that we were able to solve ourselves: PNG and JPEG upload doesn't work properly in IE7, because IE7 recognizes content types in another way than e.g. FireFox 2.x and Opera 9.x do. Surprisingly IE7 cannot show images of these content types itself!

      The following workaround allowed us to solve this problem:

      public void setPictureContentType(String contentType)
       {
       // fix for IE7
       ontentType = contentType.replaceAll("image/x-png", "image/png");
       contentType = contentType.replaceAll("image/pjpeg", "image/jpeg");
       //
       this.pictureContentType = contentType;
       }


      Any comments?

        • 1. Re: Do file upload component support jpeg and png only?
          shakenbrain

          You can upload any kind of file with the file upload component. The seamspace example, however, accepts only certain types of image files. I believe it looks at the content-type of the uploaded file and rejects it when not one of the accepted types.

          • 2. Re: Do file upload component support jpeg and png only?
            nhpvti

             

            "shakenbrain" wrote:
            You can upload any kind of file with the file upload component.


            Yes, I can upload any content and I can see binary data of the gif image in the database with contentType field set to image/gif

            But the problem is that web browsers (e.g. IE7, Firefox 2.x, Opera 9.x) don't show uploaded gif images.

            "shakenbrain" wrote:

            The seamspace example, however, accepts only certain types of image files. I believe it looks at the content-type of the uploaded file and rejects it when not one of the accepted types.


            <s:fileUpload id="picture" data="#{register.picture}" accept="image/gif"
             contentType="#{register.pictureContentType}" />


            But if you mean accept attribute, it was intended for file filtering by web browsers and is ignored.


            http://htmlhelp.com/reference/html40/forms/input.html

            The file input type creates a field through which users can upload files from their local computer or network. The VALUE attribute specifies the name of the initial file, but it is typically ignored by browsers as a security precaution. The ACCEPT attribute gives a comma-separated list of media types accepted, allowing the browser to filter out inappropriate files. Current browsers generally ignore the ACCEPT attribute.


            • 3. Re: Do file upload component support jpeg and png only?
              shakenbrain

              I guess I'm not following you. Where is this uploaded image supposed to be shown? How are you storing it?

              • 4. Re: Do file upload component support jpeg and png only?
                nhpvti

                 

                "shakenbrain" wrote:
                I guess I'm not following you. Where is this uploaded image supposed to be shown? How are you storing it?


                seamspace example, JBoss AS 4.0.5 GA, Seam 1.2.1 GA

                Images are stored in the database and shown on the start page or in the user's profile.

                It works for JPEG and PNG (with a workaround for IE7 mentioned earlier in this thread), but not for GIF.

                • 5. Re: Do file upload component support jpeg and png only?
                  pmuir

                  Yes, seamspace doesn't support gifs. But, as shakenbrain says, this is not because s:fileUpload can't upload gifs, but just due to the design of the example (in fact its because Java2D doesn't support writing to a gif, probably because of licensing issues).

                  • 6. Re: Do file upload component support jpeg and png only?
                    shakenbrain

                    From ContentServlet.java

                    String formatName = "";
                     if ("image/png".equals(contentType))
                     formatName = "png";
                     else if ("image/jpeg".equals(contentType))
                     formatName = "jpeg";
                    
                     ImageIO.write(bImg, formatName, response.getOutputStream());


                    You'd have to update this to allow for "gif" format types, but that assumes that ImageIO supports writing GIFS. Based on "http://www.gif4j.com/java-gif4j-pro-gif-image-encode-save.htm" you'll need an extra library.



                    • 7. Re: Do file upload component support jpeg and png only?
                      pmuir

                      As png is a superior format to gif, I can't see any problem here.

                      • 8. Re: Do file upload component support jpeg and png only?
                        shakenbrain

                        +1

                        • 9. Re: Do file upload component support jpeg and png only?
                          nhpvti

                           

                          "petemuir" wrote:
                          in fact its because Java2D doesn't support writing to a gif, probably because of licensing issues


                          It was my first suspicion...

                          Good news is that it is nevertheless possible and even animated:

                          "shakenbrain" wrote:

                          You'd have to update this to allow for "gif" format types, but that assumes that ImageIO supports writing GIFS. Based on "http://www.gif4j.com/java-gif4j-pro-gif-image-encode-save.htm" you'll need an extra library.



                          "petemuir" wrote:
                          png is a superior format to gif


                          The same said our web design pro. But he said also that older web browsers may have trouble with PNG format. Mail clients consuming HTML emails is another case. I'll ask him to post a question in according forum(s)

                          Thank you both for your prompt and professional assistance
                          :-)

                          More critical is requirement to have animated images.
                          PNG does not support this.
                          Hopefully one of animation extensions (MNG or APNG or ANG or ... ) somtime will be widely adopted

                          http://www.xs4all.nl/~collin/png-eng.html


                          * A new controversy has arissen: Unisys now wants to charge every website that uses GIFs that were made with suspect software (i.e. software that has no Unisys license for LZW compression) 5000 US Dollar.
                          * The PNG group has started developing an animation format to help replace animated GIFs. This format is called MNG.


                          http://en.wikipedia.org/wiki/PNG

                          PNG gained some additional popularity in August 1999, after Unisys terminated its royalty-free patent licenses to developers of free software and non-commercial software.