Grails 2.5.11 / Postgresql 10 , Upload Image and Display in GSP

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


Grails 2.5.11 / Postgresql 10 , Upload Image and Display in GSP



Hi i am new to grails and postgresql and i am trying to make a form that stores user's data and i want to be able to upload multiply photos.



service:


Cars carInstance = new Cars()
carInstance.carimg = params.carimg.getBytes()



gsp:


<input type="file" id="carimg" name="carimg" multiple />



and i call a saveCar action in controller that save all the data user will input.



And i want to display the data with the image in a showCar gsp this way :


<img src="${createLink(controller: 'garage', action: 'getImage', params: ['id': Cars.id])}"/>



also the getImage action that get the image and pass it to gsp is this :


def getImage(){
def item = Cars.get(params.id.toLong())
byte imageInByte=item.carimg
response.contentType = 'image/png'
response.outputStream << imageInByte
response.outputStream.flush() }



In the gsp it appears a blank border with an image in left corner that means image not found probably.
If i convert binary data to string it displays the right photo name.
Any suggestions ? The problem is in the way i store the image or the way i try to display a binary data to image ?









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Makefile test if variable is not empty

Will Oldham

'Series' object is not callable Error / Statsmodels illegal variable name