Skip to content

Instantly share code, notes, and snippets.

@xdougx
Forked from cgarvis/image_proxy_controller.rb
Created June 24, 2014 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xdougx/f3013241299106256e52 to your computer and use it in GitHub Desktop.
Save xdougx/f3013241299106256e52 to your computer and use it in GitHub Desktop.
require 'base64'
require 'net/http'
class ImageProxyController < ActionController::Base
def get
url = URI.parse(Base64.decode64(params[:url]))
image = Net::HTTP.get_response(url)
send_data image.body, type: image.content_type, disposition: 'inline'
end
end
require 'base64'
module ImageProxyHelper
def proxy_image_tag(source, options = nil
options[:src] = "/image_proxy/#{Base64.encode64(source)}"
tag("img", options)
end
end
require 'net/http'
class ProfileController < ActionController::Base
def image
if params['id'] == 'john'
url = URI.parse('https://pbs.twimg.com/profile_images/1979976243/potato_300.jpg')
elsif params['id'] == 'cgarvis'
url = URI.parse('https://pbs.twimg.com/profile_images/1809634620/twitter-profile.png')
end
unless url == nil
image = Net::HTTP.get_response(url)
send_data image.body, type: image.content_type, disposition: 'inline'
else
send_file 'default_image_path.jpg'
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment