All threads / How to download multiple files from s3 on fly?
Ask A Question

Notifications

You’re not receiving notifications from this thread.

How to download multiple files from s3 on fly?

mamatharao asked in Rails

Hi,

I am able to download files from s3 as a zip by using below mentioned code.

require 'open-uri'

def download_all_files
folder_path = "#{Rails.root}/public/downloads/"
zipfile_name = "#{Rails.root}/public/archive.zip"

FileUtils.remove_dir(folder_path) if Dir.exist?(folder_path)
FileUtils.remove_entry(zipfile_name) if File.exist?(zipfile_name)
Dir.mkdir("#{Rails.root}/public/downloads")

@model_object.each do |attachment|
open(folder_path + "#{attachment.avatar.file.filename}", 'wb') do |file|
file << open("#{attachment.avatar.url}").read
end
end

input_filenames = Dir.entries(folder_path).select {|f| !File.directory? f}

Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
input_filenames.each do |attachment|
zipfile.add(attachment,File.join(folder_path,attachment))
end
end

send_file(File.join("#{Rails.root}/public/", 'archive.zip'), :type => 'application/zip', :filename => "#{Time.now.to_date}.zip")

end

But by using this code, that files are storing in my application. Is there any way to download files directly from s3 or is there a way to remove files which are stored in public folder.

This is a pervasive problem that I still haven't found a solution for.

Select “Standard” if you only plan to upload small amounts of data. Select “Reduced Redundancy” if you plan to upload larger amounts of data. It help me to download document from https://www.zodiacsigns-horoscope.com/chinese-horoscope/sheep-2023/

Thanks for sharing. The solution has not known. free games unblocked

Deleting files in a shared folder, if not done correctly. Then you can specify at once to read files from the directory and delete them.

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 68,099+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more. Icons by Icons8

    © 2022 GoRails, LLC. All rights reserved.