Skip to content

Instantly share code, notes, and snippets.

@Xosmond
Forked from prog1dev/gist:62660be194ce4aec73721a0af1665983
Last active October 20, 2017 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xosmond/f4e389961aa0424b6d47d19f3d809844 to your computer and use it in GitHub Desktop.
Save Xosmond/f4e389961aa0424b6d47d19f3d809844 to your computer and use it in GitHub Desktop.
Create zip on the fly
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