0

I'm using send_file to download a zipped file consisting of multiple images, from my rails server to my iPhone. On Rails I am using Zip::ZipOutputStream.put_next_entry which I think comes from rubyzip. On the iPhone I am using ZipArchive to unzip the file back into multiple files into memory using UnzipFileToData. The problem I run into is that the bottom portions of the images are black by random amounts. Some images have no blacked out portions, others have up to half of the bottom part of the image blacked out. The images are small, around 20 KB in size.

The problem I have is that I cannot figure out what portion of the path from rails to iPhone is causing the images to have their bottom portions blacked out.

 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?  

Anyone have any idea why the unzipped images from a multi-file zipped file would be missing random parts of the bottom part of the images?

Ben
  • 13,297
  • 4
  • 47
  • 68
James Testa
  • 2,901
  • 4
  • 42
  • 60
  • maybe the zip algorithm used in the rails app is not compatible with the iphones'? – Ben Mar 06 '13 at 04:28
  • I used unzip -vl photos.zip and got for the method Def I:N. Do you know where I can find the different zip compression methods? – James Testa Mar 06 '13 at 05:03
  • Did you download it to your phone using WIFI? I know alot of gsm providers have their own interpretation of how the internet should work and limit the size of requests. – Ben Mar 06 '13 at 05:46
  • Yes, I'm downloading to my iPhone over WiFi, but the total size of the zipped file is 300 kBytes so I don't think that is the problem, is it? – James Testa Mar 06 '13 at 16:19

1 Answers1

1

Found the solution here. My rails code originally looked like:

 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

and as the link above noted, IO.read is problematic for binary files, so I followed the link's suggestion and replaced IO.read with File.open(file, "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

and that fixed the problem!

Community
  • 1
  • 1
James Testa
  • 2,901
  • 4
  • 42
  • 60