dc10
dc10

Reputation: 2198

rails as proxy for remote file download

I am having a rails application on e.g. example.com . I am using a cloud storage provider for any kind of files (videos, images, ...). No I would like to make them available for download without exposing the url of the actual storage location. So I was thinking of a kind of proxy. A simple controller which could look like this :

data = open(params[:file])
filename = "#{RAILS_ROOT}/tmp/my_temp_file"

File.open(filename, 'r+') do |f|
  f.write data.read
end

send_file filename, ...options...

( code taken from a link ).

Point being is that I would have to download the file first. So I was wondering if it would be possible to stream the file right away without downloading from the cloud storage first.

best philip

Upvotes: 2

Views: 1468

Answers (1)

Simon Thordal
Simon Thordal

Reputation: 933

I was working on this exact issue a while ago and came to the conclusion that this would not be possible without having to download the file to your server and then pass it on to the client as you say. I'd recommend generating a signed, expiring download link that you insert into a hidden iframe whenever a user clicks a download link on your page. In this way they will get the experience of downloading from your page, without the file making an unnecessary roundtrip to your server.

Upvotes: 1

Related Questions