Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save bobzhen/624043b6e933a4e7ea88e9c8b26322f9 to your computer and use it in GitHub Desktop.
Save bobzhen/624043b6e933a4e7ea88e9c8b26322f9 to your computer and use it in GitHub Desktop.
Rails. Download remote image as attachment in browser
# in controller
# for local files
send_file '/path/to/file', :type => 'image/jpeg', :disposition => 'attachment'
# for remote files
require 'open-uri'
url = 'http://someserver.com/path/../filename.jpg'
data = open(url).read
send_data data, :disposition => 'attachment', :filename=>"photo.jpg"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment