views:

834

answers:

5

Hi guys, i have a grails project with an Image Domain Class and Controller. I just installed the grails ImageTools 1.0.4 Plugin and i would like to generate thumbnails for images wich will be uploaded.

My Image-Domain-Class:

    class Image {
byte[] data
//String name

byte[] thumbnail

static constraints = {
//name()
    data()
}
}

The "safe"-action in my Controller:

def save = {
def imageInstance = new Image(params)
def imageTool = new ImageTool()
imageTool.load(imageInstance.data)
imageTool.thumbnail(320)
imageInstance.thumbnail = imageTool.getBytes("JPEG") //Here is my problem!
if(!imageInstance.hasErrors() && imageInstance.save()) {
    flash.message = "Image ${imageInstance.id} created"
    redirect(action:show,id:imageInstance.id)
}
else {
    render(view:'create',model:[imageInstance:imageInstance])
}
}

When I start my Grails-application and uploading an image I'm getting the following error-message:

Error 200: groovy.lang.MissingMethodException: No signature of method: ImageTool.getBytes() is applicable for argument types: (java.lang.String) values: {"JPEG"} Servlet: grails URI: /grailsproject/grails/image/save.dispatch Exception Message: No signature of method: ImageTool.getBytes() is applicable for argument types: (java.lang.String) values: {"JPEG"} Caused by: groovy.lang.MissingMethodException: No signature of method: ImageTool.getBytes() is applicable for argument types: (java.lang.String) values: {"JPEG"} Class: GrailsAuthenticationProcessingFilter At Line: [57]

It says that the Method getBytes() is missing but the method is still available. My IDE intelliJ also recognizes no errors.

So what can I do? Could someone help me please? Sorry for my bad english. If you are german, please look at http://support-network.info/board/problem-mit-imagetools-getbytes-t3008.html .

A: 

Looks like that method is a fairly new addition to the class (3/6/2009). If you have verified that that method is in the ./plugins/imagetools/src/groovy/ImageTool.groovy file I'd recommend running:

grails clean

If you had been using this plugin prior it might be a cache problem.

John Wagenleitner
In my ImageTool.groovy the method is available.I did grails clean but no effect, the problem still exists.Some ideas?
whitenexx
Grails 1.0.4 or 1.1? Any previous version of the plugin exist? Problem during run-app or war deploy on non-jetty container? Tried running project both in and outside of your IDE? I've tried your code using grails 1.0.4 and 1.1 and it worked.
John Wagenleitner
A: 

The reply that you received from John sounds about right - if you have installed the new plugin and can see the code, but keep getting this error only outside IntelliJ, you should try cleaning your grails cache - it's very possible that an older copy of the plugin is precompiled on the cache.

Are you using Grails 1.1? I haven't yet tested it with the latest grails, but I understand it keeps the plugins not under the project but in a separate directory. Do let me know and I'll try it out.

Ricardo J. Méndez
+1  A: 

I use Grails 1.0.4. I could fix this error message. I just copied the getBytes() method from the git Repository of Ricardo (the plugin developer) and replaced the old one with the new one. Now everything works! I don't know where the bug was but i'm happy that i solved it.

Thank you both very much!

whitenexx
A: 

I don't know what the plugin is really giving you over using JAI directly, IMHO it isn't doing much.

I use ImageMagick out of process for my image conversion and the results are superior to what can be done with JAI from what I have seen. Of course if your doing as much traffic as Amazon running out of process is not an option, however if you need to get to revenue as quickly as possible then you might want to consider what I've done.

I use apache-commons-exec to have a nice interface around handling opening an external process and reading data from std in and out. The only thing I'm using JAI for is to read the sizes of images.

DanielHonig