I’ve grabbed the latest code base of a gem called socialstream but I’m noticing an issue with file uploads on windows machines. The issue seems to be with the code below…
# Monkey patches to Ruby on Rails
#
# Use unix file util to prove the content type sent by the browser
class ActionDispatch::Http::UploadedFile
def initialize_with_magic(*args, &block)
initialize_without_magic(*args, &block)
if (unix_file = `which file`.chomp).present? && File.exists?(unix_file)
`#{ unix_file } -v 2>&1` =~ /^file-(.*)$/
version = $1
@content_type =
if version >= "4.24"
`#{ unix_file } -b --mime-type #{ @tempfile.path }`.chomp
else
`#{ unix_file } -bi #{ @tempfile.path }`.chomp =~ /(\w*\/[\w+-\.]*)/
$1
end
end
end
alias_method_chain :initialize, :magic
end
the error is as follows
NoMethodError (undefined method
chomp' for nil:NilClass):initialize_with_magic’
social_stream-base (0.22.0) lib/rails/social_stream.rb:8:in
actionpack (3.2.5) lib/action_dispatch/http/upload.rb:39:innew'normalize_parameters’
actionpack (3.2.5) lib/action_dispatch/http/upload.rb:39:in
actionpack (3.2.5) lib/action_dispatch/http/parameters.rb:73:inblock in normalize_parameters'each’
actionpack (3.2.5) lib/action_dispatch/http/parameters.rb:73:in
actionpack (3.2.5) lib/action_dispatch/http/parameters.rb:73:innormalize_parameters'normalize_parameters’
actionpack (3.2.5) lib/action_dispatch/http/upload.rb:41:in
actionpack (3.2.5) lib/action_dispatch/http/parameters.rb:73:inblock in normalize_parameters'each’
actionpack (3.2.5) lib/action_dispatch/http/parameters.rb:73:in
actionpack (3.2.5) lib/action_dispatch/http/parameters.rb:73:innormalize_parameters'normalize_parameters’
actionpack (3.2.5) lib/action_dispatch/http/upload.rb:41:in
Is there a way to make this work on windows, either by using a gem, something i can install on windows, or rewriting the file?
Either delete or comment out the line:
This will stop it from hooking into ActionDispatch::HTTP::UploadFile#initialize
This also means you won’t get its benefit of “proving” the content-type, but I don’t know if that is really necessary for your application.