Sagarmichael
Sagarmichael

Reputation: 1624

Grails redirect after uploadForm

I am trying to redirect a page after a g:uploadForm has submitted.

my g:uploadForm action is save.

the save is as follows:

  @Transactional
def save(DesignCategory designCategoryInstance) {
    if (designCategoryInstance == null) {
        notFound()
        return
    }

    if (designCategoryInstance.hasErrors()) {
        respond designCategoryInstance.errors, view: 'create'
        return
    }

    def disotypeFile = request.getFile('disotype1')
    if(!disotypeFile.empty){
        print('here')
        def fname = disotypeFile.getOriginalFilename()
        def fileAtt = new FileAttachment()
        fileAtt.originalFilename = fname
        fileAtt.newFilename =   "disotype-"
        fileAtt.fileURI =  '/Users/work/Desktop/files/' +   fileAtt.newFilename
        disotypeFile.transferTo(new File(fileAtt.fileURI))
        response.sendError(200, 'Done')
        fileAtt.save(flush: true)
        designInstance.disotype = fileAtt;
    }

        designCategoryInstance.save flush: true,  failOnError:true

    flash.message = message(code: 'default.created.message', args: [message(code: 'designCategoryInstance.label', default: 'DesignCategory'), designCategoryInstance.id])
    redirect designCategoryInstance

}

This gives the following error:

 Cannot issue a redirect(..) here. The response has already been committed either by another redirect or by directly writing to the response.. Stacktrace follows:
 Message: Cannot issue a redirect(..) here. The response has already been committed either by another redirect or by directly writing to the response.

This does work if i take out the

    def disotypeFile = request.getFile('disotype1')

but obviously I cannot get the file.

any ideas?

Upvotes: 1

Views: 276

Answers (1)

Sergei Shushkevich
Sergei Shushkevich

Reputation: 1376

Try to remove line:

response.sendError(200, 'Done')

Upvotes: 2

Related Questions