class ElFinder2::Command::File
Output file into browser. This command applies to download and preview actions.
Public Instance Methods
execute()
click to toggle source
May need to set Content-Disposition, Content-Location and Content-Transfer-Encoding. Content-Disposition should have ‘inline’ for preview action or ‘attachments’ for download.
# File lib/el_finder2/command/resize.rb, line 9 def execute if @download data = Paperclip.io_adapters.for(@file.content) send_data(data.read, filename: @file.name, type: @file.content_type) else redirect_to @file.content.url end end
Private Instance Methods
parse_params!(params)
click to toggle source
Arguments:
target : file's hash, download : Send headers to force download file instead of opening it in the browser.
# File lib/el_finder2/command/resize.rb, line 22 def parse_params!(params) target = params[:target] fail ElFinder2::Error.new(%w(errCmdParams file)) unless target path = to_path(target) @file = ElFinder2::File.find_by_path(path) fail ElFinder2::Error.new('errFileNotFound') unless @file @download = params[:download] == '1' end