Play Framework - Image upload a mysql blob type

563 views
Skip to first unread message

Alan Souza

unread,
Feb 18, 2011, 2:44:26 PM2/18/11
to play-framework
Hi all,

Let's say I have this model:

@Entity
public class Picture extends Model {

public Blob image;
...
}

When I look the type in mysql database it is just the path to the
attachments folder (VARCHAR). Is there some way to change this to save
the binary data into mysql (BLOB) using play?

I would like to achieve this:

CREATE TABLE picture (
......
image blob,
...
);

Using JDBC to set the image:

"psmnt.setBinaryStream(3, (InputStream)fis, (int)(image.length()));"

I don't know if this makes sense at all but if not please explain me
why! Why having attachments folder into play project?

Kind Regards,

Alan Souza

Santiago Gilabert

unread,
Feb 19, 2011, 10:06:46 AM2/19/11
to play-fr...@googlegroups.com, Alan Souza
You can use the Column annotation  @Column(columnDefinition="BLOB")


@Entity
public class Picture extends Model {

@Column(columnDefinition="BLOB") 
public Blob image;
 ...
}

Regards
Santiago


--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.


fgutmann

unread,
Feb 19, 2011, 9:08:40 AM2/19/11
to play-framework
Hi Alan,

i think you should use a byte array in combination with the @Lob
annotation.

@Lob
public byte[] image;

Florian Gutmann

unread,
Feb 19, 2011, 7:36:15 AM2/19/11
to play-fr...@googlegroups.com
Hi Alan,

i think you should use a byte array in combination with the @Lob annotation.

@Lob
public byte[] image;

David González

unread,
Feb 19, 2011, 3:02:08 PM2/19/11
to play-fr...@googlegroups.com
Hello Alan, I answered you a few hours ago please read http://stackoverflow.com/questions/5045831/play-framework-uploading-images-with-mysql-blob-type :)

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To post to this group, send email to play-fr...@googlegroups.com.
To unsubscribe from this group, send email to play-framewor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/play-framework?hl=en.




--
Best wishes,
David

Reply all
Reply to author
Forward
0 new messages