Sha256: cae795abf1d60e087ec3f7d14887770bb3fa9c894247f68678157640c814cfff

Contents?: true

Size: 793 Bytes

Versions: 2

Compression:

Stored size: 793 Bytes

Contents

require 'mongo'
require 'mix-rails-core/gridfs'
require 'fileutils'

class GridfsController < ActionController::Metal
  def serve
      
    file_dir =  File.expand_path '../', "#{Rails.root.join('public')}#{env['PATH_INFO']}"
    FileUtils.mkdir_p file_dir unless Dir.exists?(file_dir)
    gridfs_file = MixRailsCore::Gridfs::read_file(env["PATH_INFO"])
    tmp_file_name = "#{Rails.root.join('public')}#{env['PATH_INFO']}"
    file_content = gridfs_file.read
    File.open(tmp_file_name, 'wb') do |f|
      f.write(file_content)
      f.close
    end

    begin
      


      self.response_body = file_content

      self.content_type = gridfs_file.content_type
    rescue
      self.status = :not_found
      self.content_type = 'text/plain'
      self.response_body = ''
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
mix-rails-0.22.0 mix-rails-core/app/controllers/gridfs_controller.rb
mix-rails-core-0.22.0 app/controllers/gridfs_controller.rb