Hi, I'm using RubyZip to compress a set of images (uploaded using Paperclip) and allow the user to download them in one file, and all works fine until I come to open an image. It wont display, and trying on Ubuntu I get the error message:
"Error interpreting JPEG image file (Not a JPEG file: starts with 0x89..."
So the user is downloading a folder, populated by files with the correct usernames, but which upon opening cannot be displayed because the computer can't display their "format".
controller:
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
Thanks!