class

Lucky::FileResponse

Inherits Lucky::Response < Reference < Object

Return a file's contents for the request.

file can be used to return a file and it's contents to the browser, or render the contents of the file inline to a web browser. Options for the method:

  • path - first argument, required. The path to the file.
  • content_type - defaults to the mime-type that corresponds to the file's extension.
  • disposition - default "attachment" (downloads file), or "inline" (renders file in browser).
  • filename - default nil. When overridden and paired with disposition: "attachment" this will download file with the provided filename.
  • status - Int32 - the HTTP status code to return with.

Examples:

class Rendering::File < Lucky::Action
  get "/file" do
    file "spec/fixtures/lucky_logo.png"
  end
end

For a plain text file with no extension, have it downloaded with the file named "custom.html" and the content_type "text/html":

class Rendering::File::CustomContentType < Lucky::Action
  get "/foo" do
    file "spec/fixtures/plain_text",
      disposition: "attachment",
      filename: "custom.html",
      content_type: "text/html"
  end
end

Constants

DEFAULT_STATUS = 200

Constructors

new(context : HTTP::Server::Context, path : String, content_type : String | Nil = nil, disposition : String = "attachment", filename : String | Nil = nil, status : Int32 | Nil = nil, debug_message : String | Nil = nil)
Source

Instance methods

content_type
Source
context
Source
debug_message
Source
disposition
Source
filename
Source
headers
Source
path
Source
status
Source