LoginSignup
16
16

More than 5 years have passed since last update.

sinatraでファイルをダウンロードさせるだけの簡単なサーバを書く

Last updated at Posted at 2013-02-20

サーバのコード

file_server.rb
requre 'sinatra'

get '/:file_name' do |file_name|
  send_file(file_name)
end

実行例

以下のようにサーバを起動

$ ruby -rubygems file_server.rb

http://localhost:4567/hoge.pngのようにブラウザからアクセスすると、サーバを起動したディレクトリ配下から該当ファイルをダウンロードしてくれる。

参考

Method: Sinatra::Helpers#send_file — Documentation for sinatra (1.3.4)

16
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
16