How to download a large file from Amazon S3 through my Rails server, gradually

I would like to read the contents of a file with S3 and pass it to the user. I have large files, so I can’t just wait until it is saved on my server and then send it to the browser using * x_send_file *, because it will take a lot of time. I would like to send content to the browser while I upload it to my server.

So all this goes through my server, like some streaming download.

+6
source share
1 answer

Yes, it is possible - just delete the remote file using Rails and temporarily save it on your server or send it directly from the buffer. The problem with this is, of course, the fact that you need to extract the file first before you can serve it. See https://www.ruby-forum.com/topic/98626 for a discussion, their solution looks something like this:

#environment.rb require 'open-uri' #controller def index data = open(params[:file]) send_data data, :filename => params[:name], ... end 
+1
source

Source: https://habr.com/ru/post/894091/


All Articles