Module Paperclip::Upfile
In: 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

Public Instance methods

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

[Source]

    # File 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"jp(e|g|eg)"            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 "js"                      then "application/js"
17:       when "csv", "xml", "css"       then "text/#{type}"
18:       else
19:         # On BSDs, `file` doesn't give a result code of 1 if the file doesn't exist.
20:         content_type = (Paperclip.run("file", "-b --mime-type :file", :file => self.path).split(':').last.strip rescue "application/x-#{type}")
21:         content_type = "application/x-#{type}" if content_type.match(/\(.*?\)/)
22:         content_type
23:       end
24:     end

Returns the file‘s normal name.

[Source]

    # File lib/paperclip/upfile.rb, line 27
27:     def original_filename
28:       File.basename(self.path)
29:     end

Returns the size of the file.

[Source]

    # File lib/paperclip/upfile.rb, line 32
32:     def size
33:       File.size(self)
34:     end

[Validate]