Rest 如何从grails中的HTTP请求获取任意文件
我正在尝试在grails中设置一个可以接受文件的web服务。如何从请求中获取文件 我正在用类似的东西测试这个Rest 如何从grails中的HTTP请求获取任意文件,rest,groovy,grails,Rest,Groovy,Grails,我正在尝试在grails中设置一个可以接受文件的web服务。如何从请求中获取文件 我正在用类似的东西测试这个 curl -d somefile.tar http://localhost:8080/MyWebS/fileWS 我的方法如下所示: def index = { switch(request.method){ case "POST": render "Ingesting file\n" request.each { println("-->
curl -d somefile.tar http://localhost:8080/MyWebS/fileWS
我的方法如下所示:
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
}
}
def索引={
开关(请求方法){
案例“职位”:
呈现“摄取文件\n”
请求,每个{
println(“-->”+it)
}
def uploadedFile=request.getFile()//如果您尝试
curl -F file=@somefile.tar http://localhost:8080/MyWebS/fileWS
然后在圣杯方面
def uploadedFile = request.getFile( 'file' )
复制它不完全是重复的。我正在尝试将其设置为使用Curl进行测试,以便调用我的Web服务的其他东西(比如从某个C#项目)只需使用名为file的参数调用我的方法?如果您只是将数据流传输到请求,您可能只想从request.inputStream读取它