Add .xlsx unzip unmodified support since .xlsx files can be a natural zip file

This commit is contained in:
2018-02-19 14:37:55 -03:00
parent 7dd1a57413
commit d6706fb45e
3 changed files with 10 additions and 4 deletions
+2 -1
View File
@@ -48,7 +48,8 @@ module Dunlop::SourceFileModel
def unzip_working_file
source_path = if original_file.try(:options).try(:[], :storage) == :s3
temp = Tempfile.new 'temp' # keep reference for tempfile till unzip completed
filename = original_file.original_filename.to_s
temp = Tempfile.new([filename, File.extname(filename)]) # keep reference for tempfile till unzip completed and keep extension preserved
temp.binmode
open( original_file.expiring_url ) { |data| temp.write data.read }
temp.close
+3 -2
View File
@@ -184,9 +184,10 @@ module Dunlop::TargetFileModel
def activate_dunlop!
end
def generate!(resource = nil)
# Allow resource as argument. Changed from resource to rsrc to be sure to avoid method naming collision confusion
def generate!(rsrc = nil)
new_record = create
new_record.resource = resource if resource.present?
new_record.resource = rsrc if rsrc.present?
new_record.execute_generation_process
new_record
end
+5 -1
View File
@@ -3,7 +3,11 @@ module Dunlop::FileZip
def self.unzip(zipped_filename, unzipped_filename)
case self.mime_type(zipped_filename)
when "application/zip"
%x[ unzip -p #{zipped_filename} > #{unzipped_filename} ]
if zipped_filename.end_with?('.xlsx') # .xlsx IS a zipfile
%x[ cp #{zipped_filename} #{unzipped_filename} ]
else
%x[ unzip -p #{zipped_filename} > #{unzipped_filename} ]
end
when "application/x-gzip"
%x[ gzip -c -d #{zipped_filename} > #{unzipped_filename} ]
when "text/plain"