Created
December 3, 2010 09:21
-
-
Save chinacheng/726759 to your computer and use it in GitHub Desktop.
zip压缩
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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