A Grails plugin to access images anywhere and make it looks as local
Groovy
Switch branches/tags
Nothing to show

README.md

grails-image-indirect-plugin

Summary

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

Simplest use:

  • Add this variable on your Config.groovy

    imageindirect.basePath='/tmp/images'

    <li>Deploy a photo (say, myPhoto.jpg) on that folder
    <li>Write anywhere on your GSP: &lt;ii:imageTag indirect-imagename="myPhoto.jpg"/&gt; 
    <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

    imageindirect.basePath='/tmp/images'

    imageindirect.category.landscapes='/tmp/landscapePhotos'

    imageindirect.category.macro='macroPhotos/'

  • 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-imagename="myAvatar.gif"/>

    <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