Skip to content

Instantly share code, notes, and snippets.

@rogsmith
Created December 14, 2015 21:34
Show Gist options
  • Save rogsmith/7ead0421e70a0edc3906 to your computer and use it in GitHub Desktop.
Save rogsmith/7ead0421e70a0edc3906 to your computer and use it in GitHub Desktop.
Save RubyZip to Paperclip
buffer_string = Zip::OutputStream.write_buffer do |zos|
zos.put_next_entry("FILENAME")
zos.write FILE_DATA
end.string
file = StringIO.new(buffer_string)
file.class.class_eval { attr_accessor :original_filename, :content_type }
file.original_filename = "#{file_name}.zip"
file.content_type = "application/zip"
document = Document.new
document.attachment = file
document.save
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment