how to upload file into server directory with grails?

前端 未结 3 1873
旧时难觅i
旧时难觅i 2020-12-10 19:35

how to upload file into server directory.. if my project at D:\\myapp and i run with cmd d:\\myapp grails run-app when i run this app and other Computer run it and upload fi

3条回答
  •  被撕碎了的回忆
    2020-12-10 20:00

    The location of your Grails app doesn't matter. You have to specify the full destination path in your controller. Here is an example

    def upload() {
        def f = request.getFile('filecsv')
        if (f.empty) {
            flash.message = 'file cannot be empty'
            render(view: 'uploadForm')
            return
        }
    
        f.transferTo(new File('D:\myapp\upload\file_name.txt')) 
        response.sendError(200, 'Done') 
    }
    

提交回复
热议问题