Skip to content

Instantly share code, notes, and snippets.

@mhgbrown
Last active November 8, 2022 15:09
Show Gist options
  • Save mhgbrown/c0e193d8f900753edfb8b1d735f1023a to your computer and use it in GitHub Desktop.
Save mhgbrown/c0e193d8f900753edfb8b1d735f1023a to your computer and use it in GitHub Desktop.
Proxy images through a Rails controller
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
Rails.application.routes.draw do
get '/image_proxy/:url', to: 'image_proxy#get'
end
@vkhang55
Copy link

Thanks. This works great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment