2013-03-06 26 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 

並解決了問題!