Module: UploadsHelper

Defined in:
app/helpers/uploads_helper.rb

Instance Method Summary collapse

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.

Parameters:

  • io (File)

    The file to test.

Returns:

  • (Boolean)


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/', '') }
   = io.original_filename.split('.')[-1].downcase
  content_types.include?(io.content_type) && extensions.include?() &&
    extensions.map(&:to_sym).include?(FastImage.type(io))
end