Zip end of central directory signature not found

1.3k Views Asked by At

I'm trying to allow for a user to upload a zipped folder containing xsl stylesheets. I then want to unzip the folder and save the folder in Rails.root/public/xsl/folderName

Here's what I'm trying in my action:

require 'zip'

Zip::File.open(params[:stylesheet].tempfile) do |zipFile|
  zipFile.each do |file|
    path = File.join(Rails.root.join('public','xsl'),file.name)
    File.open(path, 'wb') do |f|
      f.write(file)
    end
  end
end

I'm getting Zip::Error: Zip end of central directory signature not found from /GEMS/gems/rubyzip-1.3.0/lib/central_directory.rb:143:in `get_e_o_c_d`

This error is happening on the first line of the code. I've tried zipping the folder through 7Zip and sending the folder to Window's "Compressed (zipped) folder".

Thanks!

1

There are 1 best solutions below

0
AudioBubble On

Zip::Error: Zip end of central directory signature not found from /GEMS/gems/rubyzip-1.3.0/lib/central_directory.rb:143:in get_e_o_c_d

  • Error indicates: Perhaps, the .xlsx file was corrupted also You can discover that the zip is corrupted or not by trying to unzip it from your code.

  • In solutiions: The content by forced it to encode as utf-8, and handle the buffer file after the upload also extract its data after it. I suggest to use the code of roo-xls gem, and it's handle both .csv/.xlsx files very easy way.