Q:

upload image to web-app/image directory in grails

I m trying to build an app with image uploading functionality... the problem is i cannot find the way to upload an image to web-app/images directory .. I m using Grails 2.2.1 and cannot do that.. would be great if anybody can help.. thanks in advance guys!!  I have tried some codes and it is uploaded to controller but i dont find way to upload it to a directory .. i have following code for my controller: 
def file = request.getFile('image')

def name = file.getOriginalFilename()
println "file is "+name
if (file && !file.empty) {
    //I dont know how to specify directory and upload the image file, the code must be written here
    flash.message = 'Image uploaded'
}ere

A:

Firstly you should never upload images to directories of your application reason being if you are using version control (git | svn) it makes the app heavier as the files are also being version controlled.
what you can do is save the images at some other location and save the location path in Config.groovy
    imageUpload.path='your location'

and where ever needed access this location as 
    grailsApplication.config.imageUpload.path

now create a form using <g:uploadForm> tag or you can use normal <form> tag but make sure to change the enctype attribute to multipart/form-data
have a look at a demo form 
    <g:uploadForm action="uploadImage">
        <input type="file" name="image">
        <input type="submit" value="Upload Image">
    </g:uploadForm>

Now in your controller you have the action uploadImage
    def uploadImage(){
      def file=request.getFile('image')
      String imageUploadPath=grailsApplication.config.imageUpload.path
      try{
         if(file && !file.empty){
         file.transferTo(new File("${imageUploadPath}/${file.name}"))
         flash.message="your.sucessful.file.upload.message"
         }
         else{
         flash.message="your.unsucessful.file.upload.message"
         }
      }
      catch(Exception e){
         log.error("Your exception message goes here",e)   
      }

    }

This will help in uploading your image but not in your web-app/images directory. 
But if you still want to transfer it to you web-app/images directory you can set the path to web-app/images directory in your Config.groovy as stated above.

