Ruby 如何从WEBrick表单上载创建图像文件
不确定如何将FormData转换为实际文件。具体来说,是一个图像Ruby 如何从WEBrick表单上载创建图像文件,ruby,webrick,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 t
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
由此:
req不是表单数据我认为您应该使用
do_POST
而不是do_GET
我已经更改为do_POST
,结果是一样的。没有req.filedata
,您应该使用您已经指定的filedata
变量:f.syswrite filedata
@DaKaZ-谢谢,我从帖子中复制了它(我修复了链接)-但我相信你的错误是正确的,所以我也修复了它。。。
server.mount '/post', 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