2013-03-06 59 views
0

我使用send_file从多个图像下载一个压缩文件,从我的Rails服务器到我的iPhone。在Rails上,我使用Zip :: ZipOutputStream.put_next_entry,我认为它来自rubyzip。在iPhone上,我使用ZipArchive使用UnzipFileToData将文件解压缩到多个文件中。我碰到的问题是,图像的底部是随机数量的黑色。有些图像没有黑色部分,其他图像最多有一半的图像底部被黑掉。图像很小,大小约为20 KB。从rails下载到iPhone压缩文件丢失部分

我遇到的问题是,我无法弄清楚从轨道到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? 

任何人有任何想法,为什么从一个多文件解压缩后的图像压缩文件会丢失图像的底部的随机配件?

+0

也许在rails应用中使用的zip算法与iphones的不兼容? – 2013-03-06 04:28:08

+0

我用unzip -vl photos.zip获得Def I:N的方法。你知道我在哪里可以找到不同的zip压缩方法吗? – 2013-03-06 05:03:08

+0

你是否使用WIFI将它下载到手机中?我知道很多gsm提供商对互联网应该如何工作和限制请求的大小有自己的解释。 – 2013-03-06 05:46:38

回答

1

找到解决方案here。我的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是二进制文件有问题,所以我跟着链接的建议,并与File.open更换IO.read(文件,“RB “){| f | f.read} as

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 

并解决了问题!