8 Replies Latest reply on Oct 23, 2008 8:45 AM by swathis

    how to store image to database

    swathis

      Hi All,
      Any body know how to store an image to database(oracle 10g) using hibernate entity and richfaces. I am trying to store an image to the database but it is not getting stored in database.... can any body help me out how to solve this problem.
                   Thanking in advance


      Swathi

        • 1. Re: how to store image to database

          Ask at the Hibernate forum.

          • 2. Re: how to store image to database
            swathis

            I want it to be done in seam framework, as seam framework internally uses hibernate, am asking how to do using hibernate entity.....

            • 3. Re: how to store image to database

              Yes, Seam supports Hibernate (and other JPA providers). You want to save a byte[] using a particlular JPA provider to a particular database. It's just an entity that should be persisted to a database, which has nothing to do with Seam.


              I suggest, again, you ask at the Hibernate forum.

              • 4. Re: how to store image to database
                shane.bryzak

                Look at the Seamspace example, in particular RegisterAction.uploadPicture().

                • 5. Re: how to store image to database
                  • 6. Re: how to store image to database
                    swathis
                    Yeah Daniel I got it... it worked perfectly.. but again I got one small problem.... I hope u can help me out...
                    Actually it uploads all types of files... but I want only images like png,gif,bmp,jpg to be uploaded... I have tried it by making small changes in xhtml code like

                    xhtml:
                    ------
                      <s:fileUpload id="file"
                                data="#{attachmentHome.instance.data}" accept="jpg,png,bmp,gif"
                                contentType="#{attachmentHome.instance.contentType}"
                                fileName="#{attachmentHome.instance.name}"
                                fileSize="#{attachmentHome.instance.size}"/>
                    • 7. Re: how to store image to database
                      swathis

                      Yeah I have tried it also


                      <s:fileUpload id="file" data="#{attachmentHome.instance.data}" accept="image/jpg,image/png,image/bmp,image/gif" contentType="#{attachmentHome.instance.contentType}" fileName="#{attachmentHome.instance.name}" fileSize="#{attachmentHome.instance.size}" />



                      its not working...... can u help me

                      • 8. Re: how to store image to database
                        swathis

                        I have written persist method in action class (i.e in attachmentHome.java) so now I can restrict others file from uploading...


                        attachmentHome.java


                         @Override
                            public String persist(){
                                 if(!(attachmentcontentType == "jpg,png,gif,bmp") && 
                                           attachmentcontentType != null){
                                      
                                      facesMessages.add("Content type is not Image");
                                 }
                                  return "/attachment.xhtml";
                                 
                            }



                        it worked....