Class: CarrierWave::SanitizedFile

Inherits:
Object
  • Object
show all
Defined in:
mod/carrierwave/lib/carrier_wave/file_card_uploader.rb

Instance Method Summary collapse

Instance Method Details

#content_typeObject



239
240
241
242
243
244
245
246
247
248
# File 'mod/carrierwave/lib/carrier_wave/file_card_uploader.rb', line 239

def content_type
  # the original content_type method doesn't seem to be very reliable
  # It uses declared_content_type  - which sometimes returns "text/plain" for asset
  # files for unknown reasons.  (we switch the order and use it as the third option)
  @content_type ||=
    guessed_safe_content_type ||
    identified_content_type ||
    declared_content_type ||
    Marcel::MimeType::BINARY
end

#guessed_safe_content_typeObject



250
251
252
253
254
255
256
257
258
259
260
261
# File 'mod/carrierwave/lib/carrier_wave/file_card_uploader.rb', line 250

def guessed_safe_content_type
  # overrides the default method which was returning "application/javascript" instead
  # of "text/javascript" for our .js files.
  return unless path

  type = Marcel::Magic.by_path(original_filename).to_s
  if type.start_with? "text/", "application/json'"
    type
  elsif type == "application/javascript"
    "text/javascript"
  end
end