After loosing some hair I found that IE and Chrome send zip contents in different ways. IE send in filename in params while chrome sends entire contents.
So here is how then I tackled it differently in controller file:
def bulk_requests_upload
#upload files
require 'pp'
file_name = params[:request][:bulk_requests_file]
dest_path = "tmp/dir_#{rand(9999)}/"
Dir.mkdir("#{dest_path}") rescue nil
begin #For IE and Mozilla
uploaded_zipfile_path = File.join(dest_path,file_name.original_filename) if file_name.original_filename
uploaded_file= File.new("#{uploaded_zipfile_path}","wb")
uploaded_file.write file_name.read
uploaded_file.close
rescue # For Chrome
uploaded_zipfile_path = File.join(dest_path,'new_file.zip')
uploaded_file= File.new("#{uploaded_zipfile_path}","wb")
uploaded_file.write file_name
uploaded_file.close
end
#unzip files
system "unzip -o #{uploaded_zipfile_path} -d #{dest_path}"
#find csv in uploaded files
csv_file_path = find_csv_file(dest_path)
#import csv
req_imports = ImportRequests.new
req_imports.import_file(csv_file_path)
@errors = req_imports.errors
#remove uploaded files
system "rm -rf #{csv_file_path}"
system "rm -rf #{uploaded_zipfile_path}"
system "rm -rf #{dest_path}*"
system "rm -rf #{dest_path}"
@errors.compact!
if @errors.size != 0
render 'requests/bulk_requests'
else
flash[:notice] = "Successfully imported requests"
redirect_to :action=> 'list_my'
end
end
Another finding here was defining the destination directory for unzip command.
system "unzip -o #{uploaded_zipfile_path} -d #{dest_path}"
I am still to find a good way to delete those randomly named empty directories getting piled up at the server.
The first two rm commands work, but
system "rm -rf #{dest_path}*"
says rm: failed the directory is not empty
which is BS.. because the directories, I swear, are empty.
Anyway, as soon as I find it out there will be another post. :-)