Sha256: 7f6ca1d7cc46b3f7b41485982abd9d1888e3eb6b6d3c0c95d42477bcbdba23d4

Contents?: true

Size: 513 Bytes

Versions: 11

Compression:

Stored size: 513 Bytes

Contents

class BrickLayer::ServeGridFsFile
  class << self
    def call(env)
      if env["PATH_INFO"] =~ /^\/files\/(.+)$/
        process_request(env, $1)
      end
    end
    
    private  
    
    def process_request(env, key)
      begin
        Mongo::GridFileSystem.new(Mongoid.database).open(key, 'r') do |file|
          [200, { 'Content-Type' => file.content_type }, [file.read]]
        end
      rescue
        [404, { 'Content-Type' => 'text/plain' }, ['File not found.']]
      end
    end
    
  end  
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
brick_layer-0.10.6 lib/brick_layer/serve_grid_fs_file.rb
brick_layer-0.10.5 lib/brick_layer/serve_grid_fs_file.rb
brick_layer-0.10.3 lib/brick_layer/serve_grid_fs_file.rb
brick_layer-0.10.2 lib/brick_layer/serve_grid_fs_file.rb
brick_layer-0.10.1 lib/brick_layer/serve_grid_fs_file.rb
brick_layer-0.10.0 lib/brick_layer/serve_grid_fs_file.rb
brick_layer-0.9.6 lib/brick_layer/serve_grid_fs_file.rb
brick_layer-0.9.4 lib/brick_layer/serve_grid_fs_file.rb
brick_layer-0.9.2 lib/brick_layer/serve_grid_fs_file.rb
brick_layer-0.9.1 lib/brick_layer/serve_grid_fs_file.rb
brick_layer-0.9.0 lib/brick_layer/serve_grid_fs_file.rb