2011-02-01 9 views

Trả lời

12

Bạn chỉ cần phải chắc chắn để gửi các tiêu đề:

Content-Disposition: attachment; filename=song.mp3; 
Content-Type: application/octet-stream 
Content-Transfer-Encoding: binary 

Phương pháp send_file nào đó cho bạn:

get '/:file' do |file| 
    file = File.join('/some/path', file) 
    send_file(file, :disposition => 'attachment', :filename => File.basename(file)) 
end 
+0

+1 đánh bại tôi vào nó và một lời giải thích tốt hơn nhiều so với tôi viết lên. –

+0

Đây là [tài liệu cho 'send_file'] (http://sinatra.rubyforge.org/api/classes/Sinatra/Streaming.html#M000022). – Phrogz