Last active
April 29, 2020 12:48
-
-
Save prog1dev/62660be194ce4aec73721a0af1665983 to your computer and use it in GitHub Desktop.
download_zip method without temp files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def download_zip(image_list) | |
unless image_list.blank? | |
file_name = 'pictures.zip' | |
stringio = Zip::ZipOutputStream::write_buffer do |z| | |
image_list.each do |img| | |
title = img.title | |
title += '.jpg' unless title.end_with?('.jpg') | |
z.put_next_entry(title) | |
z.print IO.read(img.path) | |
end | |
end | |
send_data stringio.string, :type => 'application/zip', :disposition => 'attachment', :filename => file_name | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment