send_file

File sending for Rack applications.

Usage

Make sure your application implements two methods: env and halt, where env returns a hash with the Rack environment and halt returns an array response like [status, headers, [body]].

Using Cuba

require "cuba"
require "send_file"

Cuba.plugin(SendFile)

Cuba.define do
  on "foo" do
    send_file("foo.pdf")
  end
end

Using Hobbit

require "hobbit"
require "send_file"

class App < Hobbit::Base
  include Sendfile

  get "/foo" do
    send_file("foo.pdf")
  end
end

Attachments

For attachments, it's recommended to use the HTML5 download attribute.

<a href="/foo" download>Download foo.pdf</a>

You can specify a filename too:

<a href="/foo" download="bar.pdf">Download bar.pdf</a>

Installation

$ gem install send_file