0

我正在使用 RubyZip 压缩一组图像(使用 Paperclip 上传)并允许用户将它们下载到一个文件中,并且在我打开图像之前一切正常。它不会显示,在 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

谢谢!

4

1 回答 1

0

0x89表示它是PNG。要么它正在由您的过程转换,要么它一开始就不是 JPEG。

于 2010-07-21T11:33:03.693 回答