Generating Password Protected Zip files using Ruby on Rails
Ruby on Rails, Technology
This blog will guide you on how to create a Ruby on Rails application and add rubyzip which used to make zip files with Password Protection.
Let’s have a brief introduction about Password Protection using rubyzip. If you are familiar with rubyzip and Password Protection, then directly go to the Implementation section.
What is Rubyzip?
- It’s a ruby gem (library) that is used to read and write zip files.
- rubyzip provides you with the power of reading and writing zip files and also makes password-protected zip files.
- Complete password protected reading and writing of zip files
- rubyzip provides traditional password protection.
- Ruby 1.9.2 or greater
- Technology: Ruby on Rails
- Versions: ruby 2.5.1p57 & rails 5.2.4
- Git Repository: https://github.com/jigarshah8055/zipper
- Create a new rails app
$ rails new zipper --database=postgresql
- Now put below gem in the `Gemfile` as
gem 'rubyzip', '>= 1.0.0'
Don’t forget to bundle 😉
- Generate a controller with the `create` and `new` method
rails g controller zipping_folders new
- Simply set the root path to zipping_folders new method and make resource path for only create method in routes.rb
resources :zipping_folders, only: [:create]
- Now make a form in new.html.erb with one file tag to choose files and two input fields that define zip file name and password respectively.
- You have to write below code in zipping_folders_controller.rb.
Bingooo!!! That’s it..!!!
- Start your rails server and check it on the localhost.
You can find complete codebase here.
Read Also : File Upload with Box Using Ruby on Rails
Consulting is free – let us help you grow!
I am a Ruby on Rails Developer. I like to to investigate requirements, design, execute, analyse, test, and upgrade the software/applications. Outside of the tech world, I’m a Photography fan. I’m a nature, music and movie lover and do some of my best work while listening to my favourite albums.
Choose Your Language
Subscribe to Our Newsletter
- Digital Marketing
- IT Consulting
- Project Management