Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

43 lines (35 sloc) 1.003 kb
module Paperclip
class UploadedFileAdapter < AbstractAdapter
def initialize(target)
@target = target
cache_current_values
if @target.respond_to?(:tempfile)
@tempfile = copy_to_tempfile(@target.tempfile)
else
@tempfile = copy_to_tempfile(@target)
end
end
class << self
attr_accessor :content_type_detector
end
private
def cache_current_values
@original_filename = @target.original_filename
@content_type = determine_content_type
@size = File.size(@target.path)
end
def content_type_detector
self.class.content_type_detector
end
def determine_content_type
content_type = @target.content_type.to_s.strip
if content_type_detector
content_type = content_type_detector.new(@target.path).detect
end
content_type
end
end
end
Paperclip.io_adapters.register Paperclip::UploadedFileAdapter do |target|
target.class.name.include?("UploadedFile")
end
Jump to Line
Something went wrong with that request. Please try again.