module ActionDispatch::Http::UploadedFile

def self.extended(object)

def self.extended(object)
  object.class_eval do
    attr_accessor :original_path, :content_type
    alias_method :local_path, :path if method_defined?(:path)
  end
end

def original_filename

The Windows regexp is adapted from Perl's File::Basename.
those which give the lone filename.
(and perhaps other broken user agents) without affecting
This handles the full Windows paths given by Internet Explorer
Take the basename of the upload's original filename.
def original_filename
  unless defined? @original_filename
    @original_filename =
      unless original_path.blank?
        if original_path =~ /^(?:.*[:\\\/])?(.*)/m
          $1
        else
          File.basename original_path
        end
      end
  end
  @original_filename
end