module Paperclip::Upfile
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")
Public Instance Methods
content_type()
click to toggle source
Infer the MIME-type of the file from the extension.
# File lib/dm-paperclip/upfile.rb, line 8 def content_type type = (self.path.match(/\.(\w+)$/)[1] rescue "octet-stream").downcase case type when %r"jp(e|g|eg)" then "image/jpeg" when %r"tiff?" then "image/tiff" when %r"png", "gif", "bmp" then "image/#{type}" when "txt" then "text/plain" when %r"html?" then "text/html" when "js" then "application/js" when "csv", "xml", "css" then "text/#{type}" else # On BSDs, `file` doesn't give a result code of 1 if the file doesn't exist. content_type = (Paperclip.run("file", "-b --mime-type :file", :file => self.path).split(':').last.strip rescue "application/x-#{type}") content_type = "application/x-#{type}" if content_type.match(/\(.*?\)/) content_type end end
original_filename()
click to toggle source
Returns the file's normal name.
# File lib/dm-paperclip/upfile.rb, line 27 def original_filename File.basename(self.path) end
size()
click to toggle source
Returns the size of the file.
# File lib/dm-paperclip/upfile.rb, line 32 def size File.size(self) end