File_validators

screenshot of File_validators
rails

Adds file validators to ActiveModel.

Overview

The File Validators gem offers a powerful solution for adding file size and content type validations to ActiveModel, which is widely used in Ruby on Rails applications. With this gem, developers can ensure that only valid files are processed during uploads, enhancing both the reliability and security of file handling. While it supports various versions of ActiveModel and Rails, it has been designed to seamlessly integrate with popular file uploading libraries like CarrierWave, Paperclip, and Dragonfly. This adaptability makes it an essential tool for developers looking to safeguard their applications against unwanted files.

With the release of version 2.2, users will need to ensure they are using the appropriate ActiveModel versions, as earlier ones will not be supported. The validators work before and after uploads, allowing for comprehensive checking of file submissions and setting clear guidelines on acceptable file sizes and types.

Features

  • Multi-version Support: Compatible with ActiveModel versions 3.2 through 6, along with Rails versions 3.2 to 6, ensuring broad utility across projects.
  • Flexible Validations: Includes validations for file size and content type, such as :validates_file_size and :validates_file_content_type, making customization straightforward.
  • Pre-upload and Post-upload Validation: Validations can be applied both before files are uploaded and after, providing comprehensive coverage to catch errors at any stage.
  • Multiple Validators: Provides a range of options for file size validation including conditions for less than, greater than, or a specified range of bytes.
  • Configurable Content Type Validation: Users can specify allowed and excluded content types using strings, arrays, or regex, enhancing flexibility in file management.
  • Strict and Relaxed Modes: Offers two modes for content type detection; the strict mode provides better security against spoofing while relaxed mode focuses on file names for detection.
  • Customizable Error Messages: Facilitates user-friendly feedback by allowing developers to set custom error messages for invalid uploads.
  • Built-in MIME Type Analyzers: Offers various built-in analyzers to determine MIME types accurately, promoting security and confirming file integrity during uploads.
rails
Ruby on Rails

Ruby on Rails, often referred to as Rails, is an open-source web application framework written in Ruby. Known for its convention over configuration and don't repeat yourself (DRY) principles, Rails simplifies and accelerates the development of database-backed web applications.