Module | Paperclip::Upfile
In: | vendor/plugins/paperclip/lib/paperclip/upfile.rb

The Upfile module is a convenience module for adding uploaded-file-type methods to the `File` class. Useful for testing.

      user.avatar = File.new("test/test_avatar.jpg")

### Methods

content_type original_filename size

### Public Instance methods

content_type()

Infer the MIME-type of the file from the extension.

[Source]

        # File vendor/plugins/paperclip/lib/paperclip/upfile.rb, line 8
     8:     def content_type
     9:       type = (self.path.match(/\.(\w+)$/)[1] rescue "octet-stream").downcase
    10:       case type
    11:       when %r"jpe?g"                 then "image/jpeg"
    12:       when %r"tiff?"                 then "image/tiff"
    13:       when %r"png", "gif", "bmp"     then "image/#{type}"
    14:       when "txt"                     then "text/plain"
    15:       when %r"html?"                 then "text/html"
    16:       when "csv", "xml", "css", "js" then "text/#{type}"
    17:       else "application/x-#{type}"
    18:       end
    19:     end

original_filename()

Returns the file‘s normal name.

[Source]

        # File vendor/plugins/paperclip/lib/paperclip/upfile.rb, line 22
    22:     def original_filename
    23:       File.basename(self.path)
    24:     end

size()

Returns the size of the file.

[Source]

        # File vendor/plugins/paperclip/lib/paperclip/upfile.rb, line 27
    27:     def size
    28:       File.size(self)
    29:     end

[Validate]