Ruby on rails 在RubyonRails中获取电子邮件附件的内容类型
我需要获取发送到电子邮件的附件的内容类型…我正在从本地驱动器进行附件。。如何获取该内容类型以将其保存在数据库中。。。在邮件文件中,我尝试了以下方法。但它不起作用。请帮忙Ruby on rails 在RubyonRails中获取电子邮件附件的内容类型,ruby-on-rails,Ruby On Rails,我需要获取发送到电子邮件的附件的内容类型…我正在从本地驱动器进行附件。。如何获取该内容类型以将其保存在数据库中。。。在邮件文件中,我尝试了以下方法。但它不起作用。请帮忙 files.each do |file| attachment "application/octet-stream" do |a| a.body = file.read a.filename = file.original_filename a.content_type = `fi
files.each do |file|
attachment "application/octet-stream" do |a|
a.body = file.read
a.filename = file.original_filename
a.content_type = `file --raw --brief "#{file}"`.chomp
puts "The content type of the file is...",a.content_type
end
上面的错误显示为“缺少子类型:”错误:无法打开'56.png'(没有这样的文件或目录)“更改此行:
a.content_type = `file --raw --brief "#{file}"`.chomp
到
上述方法不起作用。。我也尝试使用mime类型gem…实现如下。。。a、 content\u type=MIME::Types.type\u for(文件)。first.content\u type。。。它不起作用。。。请帮忙
a.content_type = `file --raw --brief "#{file.original_filename}"`.chomp