I think Simon is correct but you may have to mark picture with @Lob in
your entity class to make sure the field is big enough.
@Lob
private byte[] picture;
Aaron
Simon wrote:
> Hello,
>
> I don't know anything about Hypersonic, but I've done it with Hibernate.
>
> I doubt Hypersonic has any knowledge about how to transform a FileBean
> type into a BLOB SQL type.
>
> With Hibernate, I had to provide what they call a 'UserType' that know
> how to insert a FileBean type into the BLOB type. Hypersonic should
> have a similar feature...
>
> Alternatively, you may store your file content in an array of byte[]
> and have this array stored in your entity. Hibernate as a built-in
> converter from byte[] to BLOB and Hypersonic should have something
> similar too... Make sure your file is not too big as it will store all
> the content in memory...
>
> @Entity
> public class Item extends ModelBase {
>
> private byte[] picture;
>
> }
>
> ...
>
> FileBean fileBean = ... // fomr Stripes
> Item item = ... // your entity
> ItemDao itemDao = ... // your entity manager
>
> InputStream input ;
> try {
> input = new FileInputStream(fileBean.getFile());
> byte[] content = IOUtils.toByteArray(input);
> item.setPicture(content);
> } finally {
> IOUtils.closeQuietly(input);
> }
>
> // persist your Item
> itemDao.save(item);
>
> // maybe u want delete the temporary file now...
> fileBean.delete();
>
>
>
> Note that I used IOUtils from the project Jakarta commons-io in order
> to be concise...
>
> For the question about image validation, consider using javax.imagio
> classes to have informations about the image (height, width, ...).
> Look at the static methods in ImageIO class.
>
> Hope this will help you !
>
>
> Regards,
>
> Simon
>
> 2009/3/25 AK <[email protected] <mailto:[email protected]>>
>
> I've got a page that requires the user upload a photo. I'm using
> Stripersist and having some trouble forumlating how to move foward.
>
> Per Freddy's book, I know I can set up the upload to either store
> the file
> on the file system or, I'm guessing, the DB. However, in both
> cases, I'm
> not sure how to structure my objects.
>
> Right now, I'm thinking of adding a FileBean property to my Item
> object:
>
> @Entity
> public class Item extends ModelBase {
> @OneToOne
> private Person person;
> ...
> private FileBean picture;
> ...
> }
>
> ...but how will this be represented as a column in the DB (I'm using
> Hypersonic)--as a blob?
>
> Furthermore, if I create a stand-alone class called Attachment,
> and make
> this a property in there there (and then reference Attachment from
> within
> Item), the same question.
>
> What have others done to solve this problem.
>
> Oh yeah, and if I want to restrict the type of file the user can
> upload
> (.jpg/.jpeg or .gif), does Stripes provide me the ability to
> control the
> MIME-type via validation?
>
> TIA.
>
>
> ------------------------------------------------------------------------------
> Apps built with the Adobe(R) Flex(R) framework and Flex
> Builder(TM) are
> powering Web 2.0 with engaging, cross-platform capabilities.
> Quickly and
> easily build your RIAs with Flex Builder, the Eclipse(TM)based
> development
> software that enables intelligent coding and step-through debugging.
> Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
> _______________________________________________
> Stripes-users mailing list
> [email protected]
> <mailto:[email protected]>
> https://lists.sourceforge.net/lists/listinfo/stripes-users
>
>
> ------------------------------------------------------------------------
>
> ------------------------------------------------------------------------------
> Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
> powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
> easily build your RIAs with Flex Builder, the Eclipse(TM)based development
> software that enables intelligent coding and step-through debugging.
> Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
> ------------------------------------------------------------------------
>
> _______________________________________________
> Stripes-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/stripes-users
>
------------------------------------------------------------------------------
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users