Skip to content

Instantly share code, notes, and snippets.

@sankalpk
Last active December 29, 2017 11:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sankalpk/c668b877e88b90a1216f to your computer and use it in GitHub Desktop.
Save sankalpk/c668b877e88b90a1216f to your computer and use it in GitHub Desktop.
Image proxy in Rails
class ImageProxyController
def show
image = open(params[:url]) {|f| f.read }
send_data image, type: "image/jpeg", disposition: 'inline'
end
end
http://localhost:3000/image_proxy/http%3A%2F%2Fwww.cs.cmu.edu%2F%7Echuck%2Flennapg%2Flen_std.jpg
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