If you bump into ActiveStorage::InvariableError
Turns out the content_type
of one ActiveStorage::Blob
record has invalid value (text/html
). Fixing the record as well as the application code that detected the content_type incorrectly solved the problem for me. YMMV.
The error was raised when I invoke the #variant method on an ActiveStorage Attachment object.
user.avatar.variant(resize_to_fit: [36, 36])
# ActiveStorage::InvariableError!
user.avatar.blob.content_type
# "text/html"
Backtrace:
app/models/active_storage/blob/representable.rb:38:in `variant'
app/models/active_storage/attachment.rb:66:in `variant'
app/helpers/users_helper.rb:16:in `avatar'
ActiveStorage expects these content types:
ActiveStorage.variable_content_types
=>
["image/png",
"image/gif",
"image/jpg",
"image/jpeg",
"image/pjpeg",
"image/tiff",
"image/bmp",
"image/vnd.adobe.photoshop",
"image/vnd.microsoft.icon",
"image/webp",
"image/avif",
"image/heic",
"image/heif"]
Enjoyed the post?
Clap to support the author, help others find it, and make your opinion count.