Tomás Lin’s Programming Brain Dump

Flex, Grails, Facebook, iPhone and all that Jazz

Posts Tagged ‘file upload

A Simple Grails Controller for File Management

with 7 comments

Using Grails as a CMS, often times you want your users to add and remove files to a page similar to the way assets are attached to a page in the Confluence Wiki. I recently had to write a controller to handle files upload and download, and thought it might be interesting to share this since it is done so often in the Grails world.

fileupload

Download the controller : FileResourceController.groovy
Download the view : list.gsp
Download complete sample app : uploader.zip
( to run: install grails. Invoke grails run-app. Navigate to http://localhost:8080 )

Read the rest of this entry »

Written by Tomas Lin

November 26, 2008 at 1:46 am

Posted in Uncategorized

Tagged with ,

image uploading in Grails with 5 lines of code

with 4 comments

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)}"/>

Written by Tomas Lin

April 22, 2008 at 7:40 pm