Ruby on rails 使用曲别针的字体的内容类型验证
我正试图将字体文件作为附件上传到回形针中,我遇到了这个错误Ruby on rails 使用曲别针的字体的内容类型验证,ruby-on-rails,paperclip,paperclip-validation,Ruby On Rails,Paperclip,Paperclip Validation,我正试图将字体文件作为附件上传到回形针中,我遇到了这个错误 ActiveRecord::RecordInvalid: Validation failed: File content type is invalid, File is invalid 这是我试过的 validates_attachment_content_type :file, content_type:['application/x-font-opentype','application/x-font-truetype','ap
ActiveRecord::RecordInvalid: Validation failed: File content type is invalid, File is invalid
这是我试过的
validates_attachment_content_type :file, content_type:['application/x-font-opentype','application/x-font-truetype','application/octet-stream']
还有我的模特
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
class OtherFont:s3,
:path=>“字体/:id/:样式\扩展名”,
:s3_credentials=>Proc.new{| a | a.instance.s3_credentials}
def s3_凭证
{:bucket=>ENV['bucket'],:access_key_id=>ENV['access_key_id'],:secret_access_key=>ENV['secret_access_key']
结束
结束
检测到.otf和.ttf的内容类型为“应用程序/八位字节流”
必须在/initialize/paperclip.rb中创建内容类型映射
Paperclip.options[:content_type_mappings] = {
otf: 'application/x-font-opentype',
ttf: 'application/x-font-truetype'
}
对于.woff,内容类型为“application/font-woff”。已正确检测到.woff的内容类型,不需要包含在内容类型映射中。将.otf和.ttf的内容类型检测为“应用程序/八位字节流” 必须在/initialize/paperclip.rb中创建内容类型映射
Paperclip.options[:content_type_mappings] = {
otf: 'application/x-font-opentype',
ttf: 'application/x-font-truetype'
}
对于.woff,内容类型为“application/font-woff”。已正确检测到.woff的内容类型,不需要将其包含在内容类型映射中