2011-02-01 183 views

回答

12

你只需要確保發送這些標題:

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

send_file方法會爲你:

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

+1打我給它和一個更好的解釋比我寫作。 – 2011-02-02 00:08:44

相關問題