How can I avoid "Zip end of central directory signature not found (Zip::Error)" with rubyzip?
Asked Answered
P

3

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!

Paraboloid answered 12/8, 2017 at 11:58 Comment(4)
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?Lavonlavona
@Lavonlavona 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??Paraboloid
@Paraboloid did you ever solve this?Sanderson
for me it was because the zip file didn't exist, or at least you can check the location to the zip source is correctParthenia
O
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.

Outreach answered 28/10, 2019 at 17:56 Comment(0)
J
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

Jackpot answered 1/5, 2019 at 18:36 Comment(1)
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.Heartland
C
0

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

Christelchristen answered 26/4, 2022 at 8:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.