开发者

how to get an arbitrary file from an HTTP request in grails

开发者 https://www.devze.com 2023-01-19 11:36 出处:网络
I am trying to set up a web service in grails that can accept a file. How do I get the file from the request?

I am trying to set up a web service in grails that can accept a file. How do I get the file from the request?

I am testing this with something like

curl -d somefile.tar http://localhost:8080/MyWebS/fileWS

and my method looks like the following:

def index = {
    switch(request.method){
    case "POST":
    render "Ingesting file\n"
    request.each {
    println("--> " + it)
    }
    de开发者_开发知识库f uploadedFile = request.getFile() //<--this is the line that doesnt work..what should it be?
    File f=new File('c:/dev/newfile.tar');
    uploadedFile.transferTo(f);

    break
    }
}


What happens if you try

curl -F file=@somefile.tar http://localhost:8080/MyWebS/fileWS

And then on the grails side

def uploadedFile = request.getFile( 'file' )
0

精彩评论

暂无评论...
验证码 换一张
取 消