Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在RubyonRails中获取电子邮件附件的内容类型_Ruby On Rails - Fatal编程技术网

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