Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8212343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:43:27+00:00 2026-06-07T10:43:27+00:00

Im trying to upload several (one to many) images using grails and jquery. I’ve

  • 0

Im trying to upload several (one to many) images using grails and jquery. I’ve been following this post, but I couldn’t make it so far. The thing is that it seems that everything is ok, but when you try to save images (creating a building for instance) it doesn’t save any image.

I think, the key of the problem is in the gsp params for the file types(images). These are the params that arrive to my controller:
[name:1, type:1, create:Crear,
imagesList[0].data:org.springframework.web.multipart.commons.CommonsMultipartFile@d9278f,
imagesList[0]:data:org.springframework.web.multipart.commons.CommonsMultipartFile@d9278f], action:save, controller:building]

So, I think that these params are wrong for what I wanna do. Any ideas, or sample code to fix this?? Thanks!

My save() method in the building controller

def save() {
    def buildingInstance = new Building(params)
    if (!buildingInstance.save(flush: true)) {
        render(view: "create", model: [buildingInstance: buildingInstance])
        return
    }                    
        flash.message = message(code: 'default.created.message', args: [message(code: 'building.label', default: 'Building'), buildingInstance.id])
    redirect(action: "show", id: buildingInstance.id)
}

My domains:

 class Building {

    def Integer type
    def String name

    List images = new ArrayList()    
    static hasMany = [images: Image]

    static constraints = {
        name()
        type() 
    }   

    static mapping = {
        images cascade:"all-delete-orphan"
    }

def getImagesList() {
    return LazyList.decorate(images,FactoryUtils.instantiateFactory(Image.class))
}

}

 class Image {
    def byte[] data 
    static belongsTo = [building: Building]

    boolean deleted 
    static transients = [ 'deleted' ]

    static constraints = { data(maxSize:10000000,required:true,blank:false)  }
 }

My JSP’s:

_Images.jsp

<script type="text/javascript">
function addChild() {
var childCount = ${buildingInstance?.images.size()} + 0;
var htmlId = "image" + childCount;
var deleteIcon = "${resource(dir:'images/skin', file:'icon_delete.png')}";
var templateHtml = "<div id='" + htmlId + "' name='" + htmlId + "'>\n";
templateHtml += "<input type='file' id='imagesList[" + childCount + "].data' name='imagesList[" + childCount + "].data' />\n";
templateHtml += "<span onClick='$(\"#" + htmlId + "\").remove();'><img src='" + deleteIcon + "' /></span>\n";
templateHtml += "</div>\n"; 
$("#childList").append(templateHtml);
 childCount++; 
}
</script>

<div id="childList">
    <g:each var="image" in="${buildingInstance.images}" status="i">
        <!-- Render the image template (_image.gsp) here -->
        <g:render template='image'
            model="['image':image,'i':i,'hidden':false]" />
    </g:each>
</div>
<input type="button" value="Add image" onclick="addChild();" />

_image.gsp

<div id="image${i}" class="image-div" <g:if test="${hidden}">style="display:none;"</g:if>>
    <g:hiddenField name='imagesList[${i}].id' value='${image?.id}'/>
    <g:hiddenField name='imagesList[${i}].deleted' value='false'/>

    <input type="file" name="imagesList[${i}].data"  value="${image?.data}" />

    <span class="del-image">
        <img src="${resource(dir:'images/skin', file:'icon_delete.png')}" 
            style="vertical-align:middle;"/>
    </span>
</div>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T10:43:30+00:00Added an answer on June 7, 2026 at 10:43 am

    I’ve already found where it was the mistake. Just changed the “imagesList” values in the gsp for “images” as the name in the domain and it works. The post I was following seems to be wrong.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to upload several files at once from ONE input : <input type=file
I'm trying to upload images to a php file, everything works, but sometimes when
I'm trying to upload pdf files in the server. And i;m using the following
I'm using AWS SDK for .NET to upload several images. Before making the PutObjectRequest,
I'm trying to upload a rails app to dotcloud. I'm getting this error: PG::Error
So I'm trying to upload a document to a sharepoint site using a Java
I'm trying to upload files to the blobstore in my Google App without using
I'm trying to upload a file .txt in my web space, but then the
I am trying to upload images via a form which sits in partial view
I am trying to upload pictures on the wall of Facebook using Android platform.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.