9

I'm reading a lot of zip file with rubyzip.

However this error message is always showing in only specific file even it is zip file.

/app/vendor/bundle/ruby/2.3.0/gems/rubyzip-1.2.1/lib/zip/central_directory.rb:143:in `get_e_o_c_d': Zip end of central directory signature not found (Zip::Error)

I guess this error occures in rubyzip.

How can I manage this error?

Here is my code.

url = 'http://example.zip'

zipfilename = open(url)

Zip::File.open(zipfilename, :allow_redirections => :all) do |zip_file|

   entry = zip_file.glob("*ixbrl.htm").first

   stream = entry.get_input_stream.read

   puts stream

end

Thank you!

T.Akashi
  • 1,201
  • 1
  • 13
  • 17
  • Have you tried to open that zip file with other programs? Did you verify that the zip file itself is not corrupt or that is is a multipart zip and some parts are missing? – spickermann Aug 12 '17 at 13:03
  • @spickermann Hi, thank you for response! Yes, it works fine in PHP and local Ruby program. That error is happened only in heroku. I'm not familiar about verifying that the zip file if it's corrupt.. May I ask?? – T.Akashi Aug 12 '17 at 14:28
  • @T.Akashi did you ever solve this? – ElementalStorm Dec 18 '17 at 12:09
  • for me it was because the zip file didn't exist, or at least you can check the location to the zip source is correct – medBouzid May 29 '19 at 02:34

3 Answers3

8

I faced this error when I try to extract data from a uploaded .xlsx file in my application. On my context, the .xlsx file was corrupted, so my solution was save the content (I usually handle the buffer file after the upload) as a csv file (in my application I dont need to worry about the file extension), fixing the content by force it to encode as utf-8, and extract it's data after it. here is a example of the code, I'm using roo-xls gem to handle .xls files and roo gem to handle .csv and .xlsx files.

Matheus Porto
  • 169
  • 1
  • 5
2

I ran into the same error. Also only reproducible on Heroku. The error was fixed after I added an unzip buildpack (second, after Ruby).

https://github.com/davidlibrera/heroku-buildpack-unzip

chrisM
  • 338
  • 1
  • 4
  • 9
  • 2
    I am not using Heroku but running into this issue locally. The root cause of the issue seems to be file names (in the zip) without the extensions. – Shravan Ramamurthy May 15 '19 at 21:31
0

If you're using a google docs xlsx file try checking if the access of the sheet link is public.