Guest User

Untitled

a guest
Oct 21st, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. def download_zip(image_list)
  2. unless image_list.blank?
  3. file_name = 'pictures.zip'
  4.  
  5. stringio = Zip::ZipOutputStream::write_buffer do |z|
  6. z.put_next_entry("empty_folder/") ## Create a folder
  7. image_list.each do |img|
  8. title = img.title
  9. title += '.jpg' unless title.end_with?('.jpg')
  10.  
  11. z.put_next_entry(title)
  12. z.print IO.read(img.path)
  13. end
  14. end
  15.  
  16. send_data stringio.string, :type => 'application/zip', :disposition => 'attachment', :filename => file_name
  17. end
  18. end
Add Comment
Please, Sign In to add comment