1

I have a Rails 6 app. I'm using Rmagick (which wraps ImageMagick) to process several images. I need to zip them into a single file that will be get attached to a record a la active_storage.

Here's the simplified code:

# each item is an instance of Magick::Image
files = [file1, file2, ...] 

# @TODO create a zip file here
zip = ...

some_record.some_attachment.attach(
  io: zip,
  filename: 'file_name',
  content_type: 'application/x-zip' 
)

Magick::Image has a .to_blob method which could convert each image item into a blob data string. But I can't figure out how to create a zip from these blobs. I'd prefer not to write each file to the disk, but I'm open to if that's the only way.

emersonthis
  • 32,822
  • 59
  • 210
  • 375

0 Answers0