Forked from prog1dev/gist:62660be194ce4aec73721a0af1665983
Last active
October 20, 2017 20:26
-
-
Save Xosmond/f4e389961aa0424b6d47d19f3d809844 to your computer and use it in GitHub Desktop.
Create zip on the fly
This file contains hidden or 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| | |
z.put_next_entry("empty_folder/") ## Create a folder | |
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