The controller has the next method (I'm recycling my implementation of the bootstrap-file-upload plugin):
def uploadImage() {
String baseName;
String imageExtension = uploadPhotoService.imagesExtension;
String thumbnailExtension = uploadPhotoService.thumbnailsExtension;
switch(request.method){
case "GET":
def results = []
String imagesDirectoryPath = uploadPhotoService.getImageDirectoryDestinationPath(params.idAlojamiento);
def dir = new File(imagesDirectoryPath)
if( dir.exists() ) {
dir.eachFile {
baseName = uploadPhotoService.removeFileExtension(it.getName());
results << [
name: baseName,
size: it.length(),
url: createLink(controller:'alojamiento', action:'picture', params:[imageName: baseName + "." + imageExtension, idAlojamiento: params.idAlojamiento]),
thumbnail_url: createLink(controller:'alojamiento', action:'thumbnail', params:[imageName: baseName + "." + thumbnailExtension, idAlojamiento: params.idAlojamiento]),
delete_url: createLink(controller:'alojamiento', action:'deleteImage', params:[baseName: baseName, idAlojamiento: params.idAlojamiento]),
delete_type: "DELETE"
]
}
}
render results as JSON
break;
case "POST":
(...)
In the view, there is the next line:
<g:include controller="alojamiento" action="uploadImage" params="[idAlojamiento:alojamientoInstance.id]"/>
So the Internet browser shows a text line with the content of the JSON results variable:
[{"name":"boceto escaleras patio","size":37567,"url":"/AlojamientoPrototipo/alojamiento/picture?imageName=boceto+escaleras+patio.jpg&idAlojamiento=1","thumbnail_url":"/AlojamientoPrototipo/alojamiento/thumbnail?imageName=boceto+escaleras+patio.png&idAlojamiento=1","delete_url":"/AlojamientoPrototipo/alojamiento/deleteImage?baseName=boceto+escaleras+patio&idAlojamiento=1","delete_type":"DELETE"},
(...)
I don't want to show that text line. I want to loop through all images. I think it could work:
<g:each in="${results}">
<img src="${it.thumbnail_url}"/>
</g:each>
How could I to pass the results JSON variable to the GSP view to loop through it?
<bsfu:fileUpload action="upload" controller="image"/>. Why are you usingg:includeinstead?<bsfu:fileUpload action="upload" controller="image"/>to upload the images. But my idea is to use the same controller to show the images in a twitter bootstrap carousel. That's why I'm also usingg:includein another view.