Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/63.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 如何使用曲别针4.3.2在Windows上上载csv文件_Ruby On Rails_Paperclip_Spoofing - Fatal编程技术网

Ruby on rails 如何使用曲别针4.3.2在Windows上上载csv文件

Ruby on rails 如何使用曲别针4.3.2在Windows上上载csv文件,ruby-on-rails,paperclip,spoofing,Ruby On Rails,Paperclip,Spoofing,回形针有一个众所周知的问题 我如何配置我的模型,使这个愚蠢的欺骗验证能够工作 在发现问题之前,我正在使用: validates_attachment_content_type :csv_import, :content_type => 'text/csv' 但这在某些版本的Windows上不起作用。在Windows 7 Professional上,我遇到以下错误: [paperclip] Content Type Spoof: Filename delivery_detail.csv

回形针有一个众所周知的问题

我如何配置我的模型,使这个愚蠢的欺骗验证能够工作

在发现问题之前,我正在使用:

validates_attachment_content_type :csv_import, :content_type => 'text/csv'
但这在某些版本的Windows上不起作用。在Windows 7 Professional上,我遇到以下错误:

[paperclip] Content Type Spoof: Filename delivery_detail.csv (application/octet-stream from Headers, [#<MIME::Type:0x00000005077f38 @content_type="text/csv", @raw_media_type="text", @raw_sub_type="csv", @simplified="text/csv", @media_type="text", @sub_type="csv", @extensions=["csv"], @encoding="8bit", @system=nil, @registered=true, @url=["IANA", "RFC4180"], @obsolete=nil, @docs=nil>, #<MIME::Type:0x000000050c7f60 @content_type="text/comma-separated-values", @raw_media_type="text", @raw_sub_type="comma-separated-values", @simplified="text/comma-separated-values", @media_type="text", @sub_type="comma-separated-values", @extensions=["csv"], @encoding="8bit", @system=nil, @registered=false, @url=nil, @obsolete="!", @docs="use-instead:text/csv", @use_instead=["text/csv"]>] from Extension), content type discovered from file command: text/plain. See documentation to allow this combination.
[paperclip]内容类型欺骗:Filename delivery_detail.csv(来自标题的应用程序/八位字节流,[#,#]来自扩展名),从文件命令中发现的内容类型:text/plain。请参阅文档以允许这种组合。
有没有人成功制作过回形针上传csv文件

我尝试了Github问题报告中所有可能的解决方法,但都没有奏效。我需要看到工作的例子解决方案

更新1 Sonianand 11于2014年10月2日发表评论


这是可行的,但它涉及到关闭内容验证,有更好的方法吗?

我提出了以下解决方案:

添加到模型中:

validates_attachment_content_type :my_csv_uploaded_file, content_type: ['text/plain', 'text/csv', 'application/vnd.ms-excel']
对于初始值设定项:

Paperclip.options[:content_type_mappings] = { csv: 'application/vnd.ms-excel' }
这对我有用。它是使用Windows7 Professional进行测试的