in Projects, Programming, Technology

Using rails send_file to proxy remote files

require 'uri'

class ImagesController < ApplicationController
# relays remote images so that we can encrypt them
def index
data = open(params[:src])
send_data data.read,
:type => data.content_type,
:disposition => 'inline'
end
end


Here is how to proxy an image from an HTTP server to a client using ruby on rails. This is useful when trying to proxy a request from an insecure server when your server is hosted over SSL.

What do you think?

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  1. I am relatively new to rails.
    I was trying to let clients download using send_file from amazon s3. It was not working probably because send_file cannot work with remote files/urls.
    I was desperately searching for a solution.
    Your post has saved me. Thanks