how to upload file into server directory with grails?

前端 未结 3 1871
旧时难觅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 19:55

    The destination is only a file like in Java.

    def f = request.getFile('some_file')
    
    //validate file or do something crazy hehehe
    
    //now transfer file
    File fileDest = new File("Path to some destination and file name")
    f.transferTo(fileDest)
    

    OR if you want to store it at some path relative to user home:

    def homeDir = new File(System.getProperty("user.home")) //user home e.g /home/username for unix
    File fileDest = new File(homeDir,"path/to/some_folder")
    f.transferTo(fileDest)
    

    UPDATE As per why your getFile is not working, you are not submitting your form:

    
    
                       
                        
                        
    
                
    
    
    

    Should be:

    
    
                       
                        
                        
    
                
    
    
    

    if you need to use javascript you should submit the form instead of adding a link to another page.

提交回复
热议问题