RubyZip Gem: want to archive deleted files in RoR

I want to upload photos from my site after zipping. I am using rubyZip gem but cannot encrypt deleted files. The following is the scenario:

I am trying to archive content from a server. This is something like this.

http://myApplication.s3.amazonaws.com/xxxxxxxx/image/image1.jpeg ,

So, in "zipfile.add (attachment.document_file_name, attachment.document.url)", I assigned the following values:

document_file_name = image1.jpeg / image2.jpeg / image3.jpeg document.url = http://myApplication.s3.amazonaws.com/xxxxxxxx/image

Now I get the following error:

There is no such file or directory - myApplication.s3.amazonaws.com/xxxxxxxx/image

This stone works fine if I archived files from the local file system (for example: / home / user / images), but not for deleted files.

Am I doing something wrong? Can anybody help me? Or any other stone that can do this?

Thanks, -Tahniyat

+4
source share
1 answer

What you can do is first read it, starting with s3, write it directly to the archive file (put the archive file in your temporary directory), execute it, and then delete the temp archive file. Here is a small snippet:

require 'zip/zip' s3 = Aws::S3.new(S3_KEY, S3_SECRET) bucket_gen = Aws::S3Generator::Bucket.create(s3, S3_BUCKET) archive_file = "#{Rails.root}/tmp/archive.zip" Zip::ZipOutputStream.open(archive_file) do |zos| list_of_files_to_loop.each do |file| filename = file.filename url = "#{S3_PATH}/#{filename}" signed_url = bucket_gen.get(URI.unescape(URI.parse(URI.escape(url)).path[1..-1]), 1.minute) zos.put_next_entry(filename) # Give it next file a filename zos.print(URI.parse(signed_url).read) # Add file to zip end end # Write zip file # TODO: Serve file # TODO: Delete archived file from tmp directory 

Link: http://rubyzip.sourceforge.net/classes/Zip/ZipOutputStream.html

+8
source

All Articles