Module: UploadsHelper
- Defined in:
- app/helpers/uploads_helper.rb
Instance Method Summary collapse
- #upload_remote_url(blob) ⇒ Object
-
#valid_image?(io) ⇒ Boolean
Test if the given IO object is a valid image file by content type, extension, and content test.
Instance Method Details
#upload_remote_url(blob) ⇒ Object
2 3 4 5 6 7 |
# File 'app/helpers/uploads_helper.rb', line 2 def upload_remote_url(blob) bucket = Rails.cache.fetch 'active_storage/s3/bucket' do ActiveStorage::Blob.service.bucket.name end "https://s3.amazonaws.com/#{bucket}/#{blob.is_a?(String) ? blob : blob.key}" end |
#valid_image?(io) ⇒ Boolean
Test if the given IO object is a valid image file by content type, extension, and content test.
13 14 15 16 17 18 19 |
# File 'app/helpers/uploads_helper.rb', line 13 def valid_image?(io) content_types = Rails.application.config.active_storage.web_image_content_types extensions = content_types.map { |ct| ct.gsub('image/', '') } submitted_extension = io.original_filename.split('.')[-1].downcase content_types.include?(io.content_type) && extensions.include?(submitted_extension) && extensions.map(&:to_sym).include?(FastImage.type(io)) end |