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")
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 %jp(e|g|eg)" then "image/jpeg" when %tiff?" then "image/tiff" when %png", "gif", "bmp" then "image/#{type}" when "txt" then "text/plain" when %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
Generated with the Darkfish Rdoc Generator 2.