Forked from maxivak/send_data-send_file-remote-images-download
Created
March 5, 2018 17:43
-
-
Save TranBaVinhSon/d963685f9ba9455ad9abe2b232cbcdd0 to your computer and use it in GitHub Desktop.
Rails. Download remote image as attachment in browser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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