我正在使用RubyZip压缩一组图像(使用回形针上传),并允许用户将它们下载到一个文件中,在我打开图像之前,一切都很好。它不会显示,在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
谢谢!
发布于 2010-07-21 11:33:04
0x89
表示它是一个PNG。它要么正在被你的进程转换,要么一开始就不是JPEG。
https://stackoverflow.com/questions/3298677
复制