Skip to content

Instantly share code, notes, and snippets.

@prog1dev
Last active April 29, 2020 12:48
Show Gist options
  • Save prog1dev/62660be194ce4aec73721a0af1665983 to your computer and use it in GitHub Desktop.
Save prog1dev/62660be194ce4aec73721a0af1665983 to your computer and use it in GitHub Desktop.
download_zip method without temp files
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