如何使用Ruby Grape构建流API?

时间:2014-06-26 07:51:56

标签: ruby streaming grape

我想用Grape构建一个API,它可以是通过http流的POST文件。 怎么做?

grape example的PS rack-stream无法正常工作

错误信息:HTTP / 1.1 503服务不可用

1 个答案:

答案 0 :(得分:0)

我想让葡萄可以处理这样的要求:

Net::HTTP.new('localhost', 9292).start do |h|
  req = Net::HTTP::Post.new('/api/http_streaming_post')
  File.open('binary_file.bin') do |f|
    req.body_stream = f
    req['Content-Length'] = f.lstat.size.to_s
    req['Content-Type'] = 'text/html;charset=utf-8'
    response = h.request req
  end
end

我不知道该怎么做。

找到reading body_stream in sinatra后,我改用sinatra。