Created
January 1, 2013 23:34
-
-
Save maxivak/4430975 to your computer and use it in GitHub Desktop.
Rails. Download remote image as attachment in browser
This file contains 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" |
if you are going to serve aws s3 files like this, you are gonna loose all the benefits like CDN and high availability features.
because this way you download file to the server. it become a network bottleneck.
A lot of load on server's memory. Not recommended.
what about the file after downloading? is it still persist on the server?
i think the file should be removed after the controller response
thank you
shahroon commented on 13 Nov 2019
A lot of load on server's memory. Not recommended.
maybe, pass an enum with some sensible limit?
send_data data.each(512)...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hello sir,how to get perticular url from json?
$.each(files, function(key,value){
alert(value.link)});
in my code how can i store the link value in avariable?