是否可能通过Sinatra应用程序路由处理POST方式的大文件上传,同时进行流式传输,例如:
uri = URI('http://0.0.0.0:4567/files')
file = File.open("/path/to/1.iso")
req = Net::HTTP::Post.new(uri.path)
req.content_type = 'application/octet-stream'
req['Transfer-Encoding'] = 'chunked'
req.body_stream = file
Net::HTTP.start(uri.hostname, uri.port) do |http|
http.request(req)
end
这是关于一个网络服务的问题,目前我不知道如何处理这个问题,我试图向我的实际路由发出此请求:
post '/file' do
File.open('/path/to/downloaded.iso', 'ab') do |file|
file << request.body.read
end
end
但显然它失败了:
`!! Unexpected error while processing request: closed stream`
我也无法让非流媒体版本正常工作。
非常感谢任何帮助,谢谢。