Module: Studio::ProfileImage

Defined in:
lib/studio/profile_image.rb

Constant Summary collapse

ALLOWED_CONTENT_TYPES =
%w[image/png image/jpeg image/webp].freeze
MAX_BYTES =

8 MB. Phone cameras clear this comfortably; it is a bound on abuse, not on the user's actual photo.

8 * 1024 * 1024
MESSAGE =

A human sentence for the rejection path. Kept next to the rule so the two cannot drift — a message naming the wrong limit is worse than none.

"Use a PNG, JPG, or WebP under 8 MB."

Class Method Summary collapse

Class Method Details

.acceptable?(file) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
38
39
40
41
# File 'lib/studio/profile_image.rb', line 35

def acceptable?(file)
  return false unless file.respond_to?(:content_type) && file.respond_to?(:size)
  return false unless ALLOWED_CONTENT_TYPES.include?(file.content_type)

  size = file.size
  size.is_a?(Numeric) && size.positive? && size <= MAX_BYTES
end