lib/dm-paperclip/upfile.rb in dm-paperclip-2.1.2.1 vs lib/dm-paperclip/upfile.rb in dm-paperclip-2.1.4
- old
+ new
@@ -4,15 +4,18 @@
# user.avatar = File.new("test/test_avatar.jpg")
module Upfile
# Infer the MIME-type of the file from the extension.
def content_type
- type = self.path.match(/\.(\w+)$/)[1] rescue "octet-stream"
+ type = (self.path.match(/\.(\w+)$/)[1] rescue "octet-stream").downcase
case type
- when "jpg", "png", "gif" then "image/#{type}"
- when "txt" then "text/plain"
- when "csv", "xml", "html", "htm", "css", "js" then "text/#{type}"
- else "x-application/#{type}"
+ when %r"jpe?g" 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 "csv", "xml", "css", "js" then "text/#{type}"
+ else "application/x-#{type}"
end
end
# Returns the file's normal name.
def original_filename