Class: ImgFetcher::Helpers::File
- Inherits:
-
Object
- Object
- ImgFetcher::Helpers::File
- Defined in:
- lib/img_fetcher/helpers/file.rb
Constant Summary collapse
- VALID_MIME_TYPES =
All the valid image mime types
['image/bmp', 'image/cis-cod', 'image/gif', 'image/ief', 'image/jpeg', 'image/jpeg', 'image/jpeg', 'image/pipeg', 'image/svg+xml', 'image/tiff', 'image/tiff', 'image/x-cmu-raster', 'image/x-cmx', 'image/x-icon', 'image/x-portable-anymap', 'image/x-portable-bitmap', 'image/x-portable-graymap', 'image/x-portable-pixmap', 'image/x-rgb', 'image/x-xbitmap', 'image/x-xpixmap', 'image/x-xwindowdump'].freeze
Class Method Summary collapse
-
.save(temp_file, directory) ⇒ Object
SecureRandom is to avoid collisions between already existing files.
Class Method Details
.save(temp_file, directory) ⇒ Object
SecureRandom is to avoid collisions between already existing files
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/img_fetcher/helpers/file.rb', line 15 def self.save(temp_file, directory) if VALID_MIME_TYPES.include?(temp_file.content_type) FileUtils.mv(temp_file.path, "#{directory}#{SecureRandom.hex(6)}-#{temp_file.original_filename}") true else temp_file.unlink # deletes the temp file false end end |