0

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!

wastedhours
  • 257
  • 5
  • 14

1 Answers1

0

0x89 means it's a PNG. Either it's being converted by your process, or it wasn't a JPEG to begin with.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
  • I'm not sure if it is an 0x89 (I assume it is), but the error message is being cut off. The uploaded files are JPGs, but changing the file extension to PNG in the controller code gives a new error message: "PNG file corrupted by ASCII conversion"... – wastedhours Jul 21 '10 at 11:38
  • And what does looking at the files on the server result in? – Ignacio Vazquez-Abrams Jul 21 '10 at 11:43
  • No, never mind, the file on the server is probably fine. You need to open the file for reading in binary mode or you will corrupt it. – Ignacio Vazquez-Abrams Jul 21 '10 at 11:47
  • No problems with displaying them on the server as JPGs, renders as per usual. Just the corruption error. Filesizes look pretty small as well... – wastedhours Jul 21 '10 at 11:50
  • "As JPGs" or "at all"? How sure are you that they're JPEGs? – Ignacio Vazquez-Abrams Jul 21 '10 at 11:53
  • The file extension of the pictures on my machine and on the server display is JPG. I'm not sure if that's "proof" or whether the real filetype is obscured somehow. – wastedhours Jul 21 '10 at 12:00
  • Now McAfee is blocking the downloaded images because of the Exploit-QtPICT trojan, with Ubuntu's error message being "Bogus Huffman table definition"... – wastedhours Jul 21 '10 at 14:19