简体   繁体   中英

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_send_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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM