Sha256: c6f12334380605ed4490b8f38f37ee434d4738c10c684efe53892d988b696b50

Contents?: true

Size: 978 Bytes

Versions: 15

Compression:

Stored size: 978 Bytes

Contents

require 'mongo'

class GridfsController < ActionController::Metal
  def serve
    gridfs_path = env["PATH_INFO"].gsub("/files/", "")

    database_name   = Mongoid::Config.sessions[:default][:database]
    host_and_port   = Mongoid::Config.sessions[:default][:hosts][0].split(':')

    host            = host_and_port[0]
    port            = host_and_port[1]

    username        = Mongoid::Config.sessions[:default][:username]
    password        = Mongoid::Config.sessions[:default][:password]

    con = Mongo::MongoClient.new(host, port)
    
    if username
      con.add_auth(database_name, username, password)
    end
    
    db = con.db(database_name)
    
    begin
      gridfs_file = Mongo::GridFileSystem.new(db).open(gridfs_path, 'r')
      self.response_body = gridfs_file.read
      self.content_type = gridfs_file.content_type
    rescue
      self.status = :file_not_found
      self.content_type = 'text/plain'
      self.response_body = ''
    end
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
mix-rails-0.16.0 mix-rails-core/app/controllers/gridfs_controller.rb
mix-rails-core-0.16.0 app/controllers/gridfs_controller.rb
mix-rails-0.15.0 mix-rails-core/app/controllers/gridfs_controller.rb
mix-rails-core-0.15.0 app/controllers/gridfs_controller.rb
mix-rails-0.12.2 mix-rails-core/app/controllers/gridfs_controller.rb
mix-rails-core-0.12.2 app/controllers/gridfs_controller.rb
mix-rails-0.12.1 mix-rails-core/app/controllers/gridfs_controller.rb
mix-rails-core-0.12.1 app/controllers/gridfs_controller.rb
mix-rails-core-0.11.0 app/controllers/gridfs_controller.rb
mix-rails-0.10.4 mix-rails-core/app/controllers/gridfs_controller.rb
mix-rails-core-0.10.4 app/controllers/gridfs_controller.rb
mix-rails-0.10.3 mix-rails-core/app/controllers/gridfs_controller.rb
mix-rails-core-0.10.3 app/controllers/gridfs_controller.rb
mix-rails-core-0.10.2 app/controllers/gridfs_controller.rb
mix-rails-core-0.10.1 app/controllers/gridfs_controller.rb