Sinatra Beyond Basics : Send a Zip File


To zip files and send the zipped file to the client.


Step 1

Create a bogus.txt file with:

This is a test file.

Step 2

Crete a readme.txt file with:

This is a readme.

Step 3

Create a in the current directory that includes bogus.txt and readme.txt.

Step 4

Create zipper.rb with:

require 'sinatra'

get '/' do
  filename ="./"

  send_file(filename, :filename => "", :type => "application/zip")

Step 5

Run the Sinatra app, it will send the zip file when you do a GET.


In this article you learned how to send a zip file in a Sinatra app.

Related Articles