Sunday, November 9, 2014

How to save uploaded image in grails

How to save uploaded image in grails

View


<g:form action="upload" method="post" ENCTYPE="multipart/form-data">
<div class="file-upload">
<label>Choose image</label>
<input id="fileupload" type="file" name="fileupload"/>
<input type="submit" value="Upload file" />
</div>

</g:form>

Controller


class TestController 

def index()

def upload()
if (params.fileupload)
if (params.fileupload instanceof org.springframework.web.multipart.commons.CommonsMultipartFile)
// new FileOutputStream('testimage.jpg').leftShift( params.fileupload.getInputStream() )
params.fileupload.transferTo(new File('testimage.jpg'))
else
log.error("")







How to save uploaded image in grails

No comments:

Post a Comment