A Grails plugin to serve images on your program located anywhere on your filesystem, not only on the application context path
More (short) info:
This grails plugin adds a new tag <ii:imageTag /> which allows your application to serve images located anywhere on your filesystem (outside your application context). I know. You could do it with some Apache (or other webServer) tricks, but sometimes this approach can be very convenient.
Use by example
- Add this variable on your Config.groovy
<li>Deploy a photo (say, myPhoto.jpg) on that folder <li>Write anywhere on your GSP: <ii:imageTag indirect-imagename="myPhoto.jpg"/> <li>You got it!
A bit more advanced use:
You can define categories of photos and make them accessible both on relative or absolute paths. Example:
- Add to your Config.groovy
Put on /tmp/images any photo. Say: "myAvatar.gif"
Put on /tmp/landscapePhotos , "majorca.png"
Put on /tmp/images/macroPhotos , for example, "antFace.jpg"
- Write on your GSP:
<ii:imageTag indirect-category="landscapes" indirect-imagename="majorca.png"/>
<ii:imageTag indirect-category="macroPhotos" indirect-imagename="antFace.jpg"/>
- That's it!.
From v 0.0.4 you can use the plugin to store the images uploaded on the correct disk location. Just call the storeImage method on ImageIndirectService:
File storeImage(MultipartFile multipartFile, String desiredName = null, String category = null)
From v 0.0.5 you can also define a 'last resort' default file just in case the requested one doesn't exist. This can be very useful when you need things like a default icon, default user avatar image or something like that