01
May
09

sending a file to browser in rails



I’ve been working all day today on a Rails app for a school project. After I finish it ( hopefully tommorow ), I’ll tell you the story behind it. Right now, I want to save this snippet 🙂


filename = "/var/www/myfile.xyz" 
response.headers['Content-Type'] = "application/force-download" 
response.headers['Content-Disposition'] = "attachment; filename=\"#{File.basename(filename)}\"" 
response.headers["X-Sendfile"] = filename
response.headers['Content-length'] = File.size(filename)
render :nothing => true

This snippet will allow you to download a given file from your browser. The snippet was taken from John Guenin’s website. Thank you John !

Advertisements

0 Responses to “sending a file to browser in rails”



  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Blog Stats

  • 221,338 hits

%d bloggers like this: