如何从WEBrick表单上传创建图像文件

时间:2014-04-26 17:40:03

标签: ruby webrick

不确定如何将FormData转换为实际文件。特别是图像

class Post < WEBrick::HTTPServlet::AbstractServlet
  def do_GET(request, response)
    File.new("1.png") if request.query["image"]
    # request.query["image"] is a FormData object
    # how do I interpret it and turn it into a usable file?
  end
end

..后来用于服务器挂载

server.mount '/post', Post

1 个答案:

答案 0 :(得分:1)

从此blog post

def do_POST(req, res)
  filedata= req.query["filename"]

  f = File.open("foo.out", "wb")
  f.syswrite filedata
  f.close

  puts "Saved file OK"
end