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:
#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
- defaultnil
. When overridden and paired withdisposition: "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
Defined in:
lucky/file_response.crConstant Summary
-
DEFAULT_STATUS =
200
Constructors
Instance Method Summary
- #content_type
- #context : HTTP::Server::Context
- #debug_message : String?
- #disposition : String
- #filename : String?
- #headers
- #path : String
- #status : Int
Instance methods inherited from class Lucky::Response
print
print,
status : Int
status
Instance methods inherited from class Object
blank? : Bool
blank?,
present? : Bool
present?
Constructor Detail
def self.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)
#