Class: Resizing::CarrierWave::CallbackFile
- Inherits:
-
CarrierWave::SanitizedFile
- Object
- CarrierWave::SanitizedFile
- Resizing::CarrierWave::CallbackFile
- Defined in:
- lib/resizing/carrier_wave/callback_file.rb
Overview
The file handed to CarrierWave's :cache callbacks (extension_allowlist / extension_denylist / content_type_allowlist / content_type_denylist / size_range).
The extension used by the callbacks is derived from the content type whenever the content type is known, instead of being taken from the file name as plain CarrierWave does.
A file downloaded from a Resizing URL (e.g. when it is assigned through
remote_<column>_url=) is the typical case: the last segment of the URL is the
version string (.../images/<image_id>/v<version>), which contains dots, so the
"extension" CarrierWave finds in the file name is a meaningless part of the version
(Fv_Q for /v0cRq7Yb2mZt9LxA3wN8eKd5pHs1.Fv_Q), and extension_allowlist would
reject every such file. The HTTP response carries the real content type, so it is
the reliable source.
When the content type is unknown (application/octet-stream, or a type that no
extension is registered for), the file name is used as is, as in plain CarrierWave.
Constant Summary collapse
- UNKNOWN_CONTENT_TYPE =
Content type given to files whose real type could not be determined. Carries no information about the extension, so it is treated as unknown.
'application/octet-stream'
Instance Method Summary collapse
Instance Method Details
#original_filename ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/resizing/carrier_wave/callback_file.rb', line 27 def original_filename name = super return name if name.nil? extension = extension_for_content_type return name if extension.nil? basename, current_extension = split_extension(name) return name if extensions_for_content_type.include?(current_extension.downcase) "#{basename}.#{extension}" end |