Ruby on Rails でいくつかのファイルを圧縮し、zip ファイルを tmp フォルダーに保存したいと考えています。アップローダが関連付けられた名前フィールドを持つドキュメント モデルがあります。また、Carrierwave を使用してファイルを Amazon S3 にアップロードしています。私は次のコードを持っています:
class Document < ActiveRecord::Base
mount_uploader :name, DocumentUploader
...
end
def create_zip
documents = Document.all
folder = "#{Rails.root}/tmp"
tmp_filename = "#{folder}/export.zip"
zip_path = tmp_filename
Zip::ZipFile::open(zip_path, true) do |zipfile|
documents.each do |photo|
zipfile.get_output_stream(document.name.identifier) do |io|
io.write document.name.file.read
end
end
end
end
これにより、tmp フォルダーに export.zip ファイルが作成されますが、それを開こうとすると、アーカイブ マネージャー (Mac OS X) がアーカイブの解凍を開始しますが、終了せずに解凍を続けます。私のコードには何かが欠けていると思います。zipファイルのサイズは私には理にかなっていますが、その問題があります。何かご意見は?ありがとう!