class Lucky::FileResponse

Overview

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:

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

Defined in:

lucky/file_response.cr

Constant Summary

DEFAULT_STATUS = 200

Constructors

Instance Method Summary

Instance methods inherited from class Lucky::Response

print print, status : Int status

Constructor Detail

def self.new(context : HTTP::Server::Context, path : String, content_type : String? = nil, disposition : String = "attachment", filename : String? = nil, status : Int32? = nil, debug_message : String? = nil) #

[View source]

Instance Method Detail

def content_type #

[View source]
def context : HTTP::Server::Context #

[View source]
def debug_message : String? #

[View source]
def disposition : String #

[View source]
def filename : String? #

[View source]
def headers #

[View source]
def path : String #

[View source]
def print #

[View source]
def status : Int #

[View source]