Class: PostgresqlLoStreamer::LoController
- Inherits:
-
ActionController::Base
- Object
- ActionController::Base
- PostgresqlLoStreamer::LoController
- Defined in:
- app/controllers/postgresql_lo_streamer/lo_controller.rb
Instance Method Summary collapse
Instance Method Details
#connection ⇒ Object
20 21 22 |
# File 'app/controllers/postgresql_lo_streamer/lo_controller.rb', line 20 def connection @con ||= ActiveRecord::Base.connection.raw_connection end |
#stream ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/controllers/postgresql_lo_streamer/lo_controller.rb', line 5 def stream # TODO: make this headers configurable send_file_headers!({:type => 'image/png', :disposition => 'inline'}) self.status = 200 self.response_body = Enumerator.new do |y| connection.transaction do lo = connection.lo_open(params[:id].to_i, ::PG::INV_READ) while data = connection.lo_read(lo, 4096) do y << data end connection.lo_close(lo) end end end |