Q:

Grails collect() using each{} of bytes

How can I get each image to encodeBase64 in my collection? Animal has many Images, and Image belongs to Animal.
def a = Animal.findAll().collect() { Animal an ->
    [id          : an.id,
     image       : an.imagens.caminho.each {(new File(it).bytes.encodeBase64().toString()) }
    ]
}

In my JSON only returns the path, not the bytes. How can I fix it?

A:

You just need to collect them into a list instead of using each. So your code should look like this:
def a = Animal.findAll().collect() { Animal an ->
    [id: an.id,
     image: an.imagens.caminho.collect {(new File(it).bytes.encodeBase64().toString()) }
    ]
}

