Search code examples
imagemodel-view-controllergrails

Grails image url loads but image doesn't load?


In grails, images url loads fine but image doesn't display...

def thumbphoto = {
    response.setContentType('image/jpeg')
    response.setHeader('Cache-control', 'no-cache')

    if(params.id){
      userId = params.id
    }
    if(params?.id != null && !(params?.id.empty)){ 

      params.maxWidth?: 50.00
      params.maxHeight?: 50.00
      response.outputStream << imageProxyService.loadThumbnailImage(params.id, securityService.passwordEncoder(userId.toString()))
    }
  }

User has many images This is the gsp view where i am trying to load and display images along with status updates.

<g:each in="${statusList}" status="i" var="status" status="i">
            <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">
            <tr>
              <td>
            <g:if test="${status.photo != null  && !(status.photo.empty)}" >
                  <img id="profile_photo" src="${createLink(controller:'image', action:'thumbphoto', id:status.photo, params:[maxWidth:50.0,maxHeight:50.0,id:status.id])}" alt="" title="" />

            </g:if>
            <g:else>
              <img id="profile_photo" src="${resource(dir:'images', file:'no_image_blue.gif')}" alt="No Image" width="50" height="50"/>
            </g:else>
            </td>
            <td>${status.id}: ${status.message}</td>
            </tr>
            </tr>
          </g:each>

Solution

  • Install Firebug, and go to the Net tab.

    You should see all the HTTP requests and their statuses.

    You're likely get a 404 for your image, check its location under your webapps folder...

    Again Firebug will give you all the hints and solutions.