image uploading in Grails with 5 lines of code

In your domain class, define


class Something{
byte[] image
}

in your controller, call

def image= {
def something = Something.get( params.id )
byte[] image = something.image
response.outputStream << image
}

Image gets copied to the database. You can then show it by

<img src="${createLink(controller:'something', action:'image', id: something.id)}"/>

4 thoughts on “image uploading in Grails with 5 lines of code

  1. kill-me-santa.blogspot.com

    I think you forgot to set content type in your controller.

    Thanks,
    Mikhail

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s