views:

33

answers:

1

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)
    }
    def 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
    }
}
A: 

What happens if you try

curl -F [email protected] http://localhost:8080/MyWebS/fileWS

And then on the grails side

def uploadedFile = request.getFile( 'file' )
tim_yates
So something else that would call my webservice (say from some C# project) would just have to call my method with a parameter called file?
Derek
If you're just streaming data to the request, you probably just want to read it from request.inputStream
tim_yates