Skip to content

Instantly share code, notes, and snippets.

@JunichiIto
Created December 29, 2021 09:10
Show Gist options
  • Save JunichiIto/9b736949da79c416e3fadd56c5211946 to your computer and use it in GitHub Desktop.
Save JunichiIto/9b736949da79c416e3fadd56c5211946 to your computer and use it in GitHub Desktop.
Rails 7.0 - How to fix "DEPRECATION WARNING: image/jpg is not a valid content type"

Rails 7.0 - How to fix "DEPRECATION WARNING: image/jpg is not a valid content type"

Problem

I got the following message when I updated my app to Rails 7.0.

DEPRECATION WARNING: image/jpg is not a valid content type, it should not be used when creating a blob, and support for it will be removed in Rails 7.1. If you want to keep supporting this content type past Rails 7.1, add it to `config.active_storage.variable_content_types`. Dismiss this warning by setting `config.active_storage.silence_invalid_content_types_warning = true`. (called from public_send at /Users/jnito/.rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/factory_bot-6.2.0/lib/factory_bot/attribute_assigner.rb:16)

Cause

I wrote wrong Content-type('image/jpg').

FactoryBot.define do
  factory :note do
    message { "My important note." }
    association :project
    user { project.owner }

    trait :with_attachment do
      attachment { Rack::Test::UploadedFile.new("#{Rails.root}/spec/files/attachment.jpg", 'image/jpg') }
    end
  end
end

How to fix

I have to write valid content type('image/jpeg').

 FactoryBot.define do
   factory :note do
     message { "My important note." }
     association :project
     user { project.owner }
 
     trait :with_attachment do
-      attachment { Rack::Test::UploadedFile.new("#{Rails.root}/spec/files/attachment.jpg", 'image/jpg') }
+      attachment { Rack::Test::UploadedFile.new("#{Rails.root}/spec/files/attachment.jpg", 'image/jpeg') }
     end
   end
 end
@elissonmichael
Copy link

Thanks for sharing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment