如何在grails中从HTTP请求中获取任意文件 [英] how to get an arbitrary file from an HTTP request in grails

查看:93
本文介绍了如何在grails中从HTTP请求中获取任意文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在可以接受文件的grails中设置一个web服务。如何从请求中获取文件?

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
    }
}


推荐答案

如果您尝试

What happens if you try

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

然后在grails一边

And then on the grails side

def uploadedFile = request.getFile( 'file' )

这篇关于如何在grails中从HTTP请求中获取任意文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆