Skip to content

Instantly share code, notes, and snippets.

@chinacheng
Created December 3, 2010 09:21
Show Gist options
  • Save chinacheng/726759 to your computer and use it in GitHub Desktop.
Save chinacheng/726759 to your computer and use it in GitHub Desktop.
zip压缩
require 'zip/zipfilesystem'
require 'zip/zip'
require 'uuidtools'
# 导出host中的所有附件到一个zip文件中
def export_attachments
zip_path = Dir::tmpdir + '/'+ UUID.random_create.to_s + ".zip"
zip = Zip::ZipFile.open(zip_path, Zip::ZipFile::CREATE)
self.attachments.each do |attachment|
zip.add("文件名","源文件路径")
end
zip.close
return zip_path
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment