uploading a file in grails

后端 未结 3 380
温柔的废话
温柔的废话 2021-01-02 09:17

I am trying to upload a file in grails in my gsp I have:


     

        
3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-02 09:54

    here is working file submit:

    the form (gsp)

    the controller that will store submitted file into 'D:/submitted_file':

    def index() {
        if(params.cfile){
            if(params.cfile instanceof org.springframework.web.multipart.commons.CommonsMultipartFile){
                new FileOutputStream('d:/submitted_file').leftShift( params.cfile.getInputStream() );
                //params.cfile.transferTo(new File('D:/submitted_file'));
            }else{
                log.error("wrong attachment type [${cfile.getClass()}]");
            }
        }
    }
    

    this works for me (grails 2.0.4)

提交回复
热议问题