Sha256: e644ead40ab4393667aeb3cf96dc5fc77641819298a09e61adc8dd77c8743281

Contents?: true

Size: 810 Bytes

Versions: 14

Compression:

Stored size: 810 Bytes

Contents

# Controller that serves files from the database via single action #show.
#
# If the file requested is an image redirect to Neofiles::ImagesController is made.
#
class Neofiles::FilesController < ActionController::Metal

  include ActionController::DataStreaming
  include ActionController::Redirecting
  include Rails.application.routes.url_helpers
  include Neofiles::NotFound

  def show
    file = Neofiles::File.find params[:id]

    if file.is_a? Neofiles::Image
      options = params.except(:action, :controller, :id)
      redirect_to neofiles_image_path(options), status: 301 and return
    end

    send_file_headers!({
      filename: CGI::escape(file.filename),
      type: file.content_type,
      disposition: 'inline',
    })

    self.status = 200
    self.response_body = file.data
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
neofiles-1.3.2 app/controllers/neofiles/files_controller.rb
neofiles-2.2.0 app/controllers/neofiles/files_controller.rb
neofiles-2.1.1 app/controllers/neofiles/files_controller.rb
neofiles-1.3.1 app/controllers/neofiles/files_controller.rb
neofiles-1.3.0 app/controllers/neofiles/files_controller.rb
neofiles-2.1.0 app/controllers/neofiles/files_controller.rb
neofiles-2.0.4 app/controllers/neofiles/files_controller.rb
neofiles-2.0.3 app/controllers/neofiles/files_controller.rb
neofiles-1.2.2 app/controllers/neofiles/files_controller.rb
neofiles-1.2.1 app/controllers/neofiles/files_controller.rb
neofiles-2.0.2 app/controllers/neofiles/files_controller.rb
neofiles-2.0.1 app/controllers/neofiles/files_controller.rb
neofiles-2.0.0 app/controllers/neofiles/files_controller.rb
neofiles-1.1.4 app/controllers/neofiles/files_controller.rb