1

I'm trying to upload font files as attachments in paperclip and I get this error.

ActiveRecord::RecordInvalid: Validation failed: File content type is invalid, File is invalid

Here is what I tried

validates_attachment_content_type :file, content_type:['application/x-font-opentype','application/x-font-truetype','application/octet-stream']

And my model

class OtherFont < ActiveRecord::Base
    has_many :texts
  has_attached_file :file, default_url: "/images/:style/missing.png"
   validates_attachment_content_type :file, content_type:['application/x-font-opentype','application/x-font-truetype','application/octet-stream']
  has_attached_file :file,
                    :storage => :s3,
                    :path => "fonts/:id/:style_:extension",
                    :s3_credentials => Proc.new{|a| a.instance.s3_credentials }
  def s3_credentials
    {:bucket => ENV['bucket'], :access_key_id => ENV['access_key_id'], :secret_access_key => ENV['secret_access_key']}
  end                  
end
Pamela Guerrero
  • 107
  • 2
  • 11

1 Answers1

0

The content_type for .otf and .ttf are detected as 'application/octet-stream'

You have to create a content type mapping in /initialize/paperclip.rb

Paperclip.options[:content_type_mappings] = {
   otf: 'application/x-font-opentype',
   ttf: 'application/x-font-truetype'
}

For .woff, the content_type is 'application/font-woff'. The content type for .woff is detected correctly and doesn't need to be included in content_type_mappings.