How can I download a large file from Amazon S3 through my Rails server, progressively
I would like to read a content of a file from S3 and pass it to the user. I have large files so I cannot just wait until it's saved on my server and then send it to the browser using *x_se开发者_开发问答nd_file* because it would take to much time. I would like to send the content to the browser while I am downloading it on my server.
So it all passes through my server like some kind of streamed download.
Yes, this is possible - just fetch the remote file with Rails and either store it temporarily on your server or send it directly from the buffer. The problem with this is of course the fact that you need to fetch the file first before you can serve it to the user. See https://www.ruby-forum.com/topic/98626 for a discussion, their solution is something like this:
#environment.rb
require 'open-uri'
#controller
def index
data = open(params[:file])
send_data data, :filename => params[:name], ...
end
精彩评论