| Module | XSendFile::Controller |
| In: |
lib/x_send_file/controller.rb
|
Sends the file by setting the X-Sendfile HTTP header. You web server must be configured to respond to this header, or it will not work.
Options:
Simple download:
x_send_file '/path/to/file'
Show a JPEG in the browser:
x_send_file('/path/to/image.jpg', :type => 'image/jpeg', :disposition => 'inline')
Send file using Lighttpd:
x_send_file '/path/to/file, :header => 'X-LIGHTTPD-SEND-FILE'
x_send_file‘s options and defaults mirror those of send_file. Please see ActionController::Streaming#send_file for more detailed information about the options, HTTP specs, and possible security issues.
# File lib/x_send_file/controller.rb, line 52
52: def x_send_file(path, options = {})
53: raise ActionController::MissingFile, "Cannot read file #{path}" unless File.file?(path) and File.readable?(path)
54:
55: # pull in default values for options
56: options.reverse_merge!(Plugin.options)
57: options[:length] ||= File.size(path)
58: options[:filename] ||= File.basename(path) unless options[:url_base_filename]
59:
60: # set headers & send response
61: send_file_headers! options
62: response.headers[options[:header]] = path
63: logger.info "Sending XSendFile header for #{path}" unless logger.nil?
64: render options[:render]
65: end