class ImgFetcher::Helpers::File

Constants

VALID_MIME_TYPES

All the valid image mime types

Public Class Methods

save(temp_file, directory) click to toggle source

SecureRandom is to avoid collisions between already existing files

# 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