RubyZip 将 JPG 转换为“非 JPG,以 0x89 开头”
我正在使用 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
谢谢!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
0x89
表示它是 PNG。它要么正在由您的进程进行转换,要么一开始就不是 JPEG。0x89
means it's a PNG. Either it's being converted by your process, or it wasn't a JPEG to begin with.