I would like to download http://foobar.com/song.mp3 as song.mp3
, instead of having Chrome open it in its native <audio>
player in the browser.
How can I accmplish this?
Click on "Settings" and you'll see a new page pop up in your Chrome browser window. Scroll down to Advanced Settings, click Downloads, and clear your Auto Open options. Next time you download an item, it will be saved instead of opened automatically.
Alternatively, enter chrome://settings/content/ in the address bar. On the right, go to the Content section, and click on Additional content settings. Click on PDF documents. On the next page, turn on (enable) the Download PDF files instead of automatically opening them in Chrome option.
You just need to make sure to send these headers:
Content-Disposition: attachment; filename=song.mp3;
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
The send_file
method does it for you:
get '/:file' do |file|
file = File.join('/some/path', file)
send_file(file, :disposition => 'attachment', :filename => File.basename(file))
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With