【问题标题】:how to get an arbitrary file from an HTTP request in grails如何从 grails 中的 HTTP 请求中获取任意文件
【发布时间】:2010-10-06 17:06:21
【问题描述】:

我正在尝试在 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("--> " + 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
    }
}

【问题讨论】:

标签: rest groovy grails


【解决方案1】:

如果你尝试会发生什么

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

然后在圣杯方面

def uploadedFile = request.getFile( 'file' )

【讨论】:

  • 所以其他会调用我的 web 服务(比如来自某些 C# 项目)的东西只需要使用名为 file 的参数调用我的方法吗?
  • 如果您只是将数据流式传输到请求中,您可能只想从 request.inputStream 中读取它
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-30
  • 1970-01-01
  • 2020-02-12
相关资源
最近更新 更多