views:

28

answers:

1

I am on the photo sharing site , and i want to give functionality to download all the images available in the gallery ,, I have taken gallery in a relation where i can get all the iamges by @gallery.uploads ,

Now what i want is to download this all files , or if its possible to create any zipfile so that we can download that one file containing uploads inside the gallery ,

thanks

+1  A: 

Use the rubyzip gem in order to create zipfiles on the server-side:

   require 'zip/zip'

   Zip::ZipFile.open("my.zip", Zip::ZipFile::CREATE) {
    |zipfile|
    puts zipfile.read("first.txt")
    zipfile.remove("first.txt")
   }

Add the images to the zipfile and use sendfile in the rails-application to send the files to the browser. Read the documentation on Zip::Zipfile and sendfile for the missing bits.

jhwist
and how can i add images inside it? will you please elaborate your answer sir ?
Arpit Vaishnav
That depends on how the images are stored on the server. Does `@gallery.uploads` return the image-data or just a path to the file?
jhwist
hum i got the way to download by temp file ,whch creates tmp file ,put image files , and create on clien side with send_file thanks
Arpit Vaishnav
Can you mark the answer as accepted, then?
jhwist