lib/paperclip/io_adapters/file_adapter.rb in paperclip-3.0.2 vs lib/paperclip/io_adapters/file_adapter.rb in paperclip-3.0.3
- old
+ new
@@ -54,23 +54,25 @@
end
private
def copy_to_tempfile(src)
- dest = Tempfile.new(original_filename)
+ extension = File.extname(original_filename)
+ basename = File.basename(original_filename, extension)
+ dest = Tempfile.new([basename, extension])
dest.binmode
FileUtils.cp(src.path, dest.path)
dest
end
def best_content_type_option(types)
- types.reject {|type| type.content_type.match(/\/x-/) }.first
+ types.reject {|type| type.content_type.match(/\/x-/) }.first.content_type
end
def type_from_file_command
# On BSDs, `file` doesn't give a result code of 1 if the file doesn't exist.
type = (self.original_filename.match(/\.(\w+)$/)[1] rescue "octet-stream").downcase
- mime_type = (Paperclip.run("file", "-b --mime :file", :file => self.path).split(/[:;]\s+/)[0] rescue "application/x-#{type}")
+ mime_type = (Paperclip.run("file", "-b --mime :file", :file => self.path).split(/[:;\s]+/)[0] rescue "application/x-#{type}")
mime_type = "application/x-#{type}" if mime_type.match(/\(.*?\)/)
mime_type
end
end
end