Rails proxy controller will not pull images correctly, how to change correctly?

I need to implement a proxy server in a Rails 3.1 application in order to overcome some cross-domain JS issues.

So far I have been looking for the source of the text of the webpage, it would seem to be right, however it usually skips the images (maybe relative paths?) On the page, and then when I direct it with the absolute path to the image, it will show ascii encoding of the image . and not an image, I think for obvious reasons from the code for someone familiar with the topic.

I was hoping someone would be able to review the following code to work properly with the proxy situation:

proxy_controller.rb:

class ProxyController < ApplicationController
  def get
    url = URI.parse(params["url"])
    result = Net::HTTP.get_response(url)
      render :text => result.body
  end
end

routes.rb:

get "proxy" => "proxy#get", :as => "proxy"

Call through:

http://<my_dev_server>/proxy?url=http://<somedomain.tld>/path/to/page/images/image.jpg

or

http://<my_dev_server>/proxy?url=http://<somedomain.tld>/path/to/page
+5
source
2
+9

, base64 encode, get on html

send_data Base64.encode64(result.body), type: result.content_type, disposition: 'inline'

html javascript,

$('#image-wrapper').html('<img src="data:image/png;base64,' + data + '" />')
0

All Articles