ruby on rails: audio/mp3 content header download

Posted by bandhunt on Stack Overflow See other posts from Stack Overflow or by bandhunt
Published on 2010-05-13T20:51:37Z Indexed on 2010/05/13 20:54 UTC
Read the original article Hit count: 271

Filed under:
|

How do you set the headers for downloads in ruby/rails?

In php I'd set the header for an mp3 download like this:

    header("Content-Transfer-Encoding: binary");
    header("Content-type: audio/mp3");
    header("Content-Disposition: attachment; filename=\"$songname.mp3\"");
    header("Content-Length: " . $size);

    @readfile("http://example.com/12345.mp3");

Seems like there should be an easy should an easy solution.

I did find this:

response.headers['Content-type'] = 'Content-type: audio/mp3'

But I'm not sure how/where the readfile would come into play and other headers.

Thanks!

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby