Skip to content
This repository

type_from_file_command method error on windows #926

inetufo opened this Issue · 7 comments

6 participants

inetufo Prem Sichanugrist diogocsc Guilherme Cassolato Simon Smith Jon Yurek

Because windows doesn't have the file command, so this line"file", "-b --mime :file", :file => self.path).split(/[:;\s]+/)[0] raises error.


can't be shown?

Prem Sichanugrist

This was fixed in 1d22cdc. Thanks for reporting in.

Prem Sichanugrist sikachu closed this

(I've posted this as a comment to the commit, but perhaps here is a better place) :

Hi, I'm running windows 7 and getting undefined method `match' for nil:NilClass

/gems/paperclip-3.1.3/lib/paperclip/content_type_detector.rb:60:in `type_from_file_command'

Guilherme Cassolato

Yep, still getting undefined method `match' for nil:NilClass after "file -b --mime ..." w/ Paperclip v3.1.4 on Windows 7.


paperclip (3.1.4) lib/paperclip/content_type_detector.rb:60:in type_from_file_command'
paperclip (3.1.4) lib/paperclip/content_type_detector.rb:16:in
paperclip (3.1.4) lib/paperclip/io_adapters/file_adapter.rb:14:in cache_current_values'
paperclip (3.1.4) lib/paperclip/io_adapters/file_adapter.rb:5:in
paperclip (3.1.4) lib/paperclip/io_adapters/registry.rb:29:in new'
paperclip (3.1.4) lib/paperclip/io_adapters/registry.rb:29:in
paperclip (3.1.4) lib/paperclip/attachment.rb:412:in post_process_style'
paperclip (3.1.4) lib/paperclip/attachment.rb:402:in
block in post_process_styles'
paperclip (3.1.4) lib/paperclip/attachment.rb:401:in each'
paperclip (3.1.4) lib/paperclip/attachment.rb:401:in
paperclip (3.1.4) lib/paperclip/attachment.rb:394:in `block (2 levels) in post_process'

Prem Sichanugrist sikachu reopened this
Guilherme Cassolato

Thanks for reopening the issue, @sikachu.

For now I've just installed File package from GnuWin32 ( and it solved the problem. I also had to add C:\Program Files\GnuWin32\bin to PATH and reboot. For me it was not a big deal since my production environment is Linux-based, but I understand this might not be considered a definitive solution for some people.

At least now we know for sure that the issue is actually related to the file command in type_from_file_command (content_type_detector.rb, line 54) on Windows. This is still strange though since the method was not supposed to be executed at all. I ran MIME::Types.type_for(@filename) in the console and it returned a non-null array as expected, so match? (line 38) should return true and the detect method (line 10) should bypass the call for type_from_file_command. It seems that MIME::Types.type_for(@filename) is returning nil when performed by paperclip instead.

My system specs:

  • Ruby: 1.9.3p194
  • Gem: 1.8.23
  • Rails: 3.2.6
  • Paperclip: 3.1.4
  • ImageMagick: 6.7.8-Q16
  • GnuWin/File: 5.03
  • OS: Win 7 (32-bit)

I hope this helps.

Simon Smith

Submitted pull request for fix


Jon Yurek

The fix for this was pulled into master not too long ago. If anyone has recurring problems from here, please open a new ticket on the issue so we can start fresh. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.