0

我正在使用 send_file 将包含多个图像的压缩文件从我的 rails 服务器下载到我的 iPhone。在 Rails 上,我使用的是 Zip::ZipOutputStream.put_next_entry,我认为它来自 ruby​​zip。在 iPhone 上,我使用 ZipArchive 使用 UnzipFileToData 将文件解压缩回多个文件到内存中。我遇到的问题是图像的底部是随机黑色的。一些图像没有被涂黑的部分,而另一些图像的底部多达一半被涂黑。图像很小,大约 20 KB。

我遇到的问题是我无法弄清楚从轨道到 iPhone 的路径的哪一部分导致图像的底部变黑。

 1.  I've ftp'ed the zipped file from my Rails server to my Mac and unzipped them and the images look fine, which means the images are getting zipped on the Rails server correctly.
 2.  I've tried reversing the order that the images are added to the zip file, but the same amounts of the bottom of the images are blacked out.
 3.  Could it be that different compression levels are being used?  

任何人都知道为什么来自多文件压缩文件的解压缩图像会丢失图像底部的随机部分?

4

1 回答 1

1

在这里找到了解决方案。我的 Rails 代码最初看起来像:

 Zip::ZipOutputStream.open(zipped_file.path) do |z|
    user_photo_array.each do |file|
        z.put_next_entry(File.basename(file))
        z.print IO.read(file)
    end
 end

并且正如上面的链接所述, IO.read 对于二进制文件是有问题的,所以我按照链接的建议将 IO.read 替换为 File.open(file, "rb"){ |f| f.read } 为

 Zip::ZipOutputStream.open(zipped_file.path) do |z|
    user_photo_array.each do |file|
        z.put_next_entry(File.basename(file))
        z.print File.open(file, "rb"){ |f| f.read }
    end
 end

这解决了问题!

于 2013-03-06T18:16:54.137 回答