RubyZip を使用して一連の画像 (Paperclip を使用してアップロード) を圧縮し、ユーザーがそれらを 1 つのファイルにダウンロードできるようにしています。画像を開くまではすべて正常に動作します。表示されず、Ubuntu で試してみると、次のエラー メッセージが表示されます。
"Error interpreting JPEG image file (Not a JPEG file: starts with 0x89..."
したがって、ユーザーは正しいユーザー名のファイルが入力されたフォルダーをダウンロードしていますが、コンピューターが「形式」を表示できないため、開くと表示できません。
コントローラ:
def zip
@product = Product.find(params[:id])
t = Tempfile.new(@product.random+rand(200).to_s)
Zip::ZipOutputStream.open(t.path) do |z|
@product.assets.each do |img|
img_path = "#{RAILS_ROOT}"+"/public"+img.data.url(:original)
file = File.open(img_path.split('?')[0])
z.put_next_entry(img.id.to_s+"_original.jpg")
z.print IO.read(file.path)
end
end
send_file t.path, :type => 'application/zip', :disposition => 'attachment', :filename => "#{@product.random}-#{rand(9999).to_s}.zip"
end
ありがとう!