Last active
December 29, 2017 11:23
-
-
Save sankalpk/c668b877e88b90a1216f to your computer and use it in GitHub Desktop.
Image proxy in Rails
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
class ImageProxyController | |
def show | |
image = open(params[:url]) {|f| f.read } | |
send_data image, type: "image/jpeg", disposition: 'inline' | |
end | |
end |
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
http://localhost:3000/image_proxy/http%3A%2F%2Fwww.cs.cmu.edu%2F%7Echuck%2Flennapg%2Flen_std.jpg |
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
get 'image_proxy/*url' => 'image_proxy#show', constraints: { :url => /.*/ } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment