class ContactFile < ActiveRecord::Base
  mount_uploader :file, ContactFileUploader
  
  belongs_to :admin
  belongs_to :contact
  
	def file_type
	
		
		mime = `file --mime -br "#{self.file.path}"`.strip.split(';')[0]
		mime
		
	end
  
  
  before_create { generate_token() }
  
  def generate_token()
    begin
        self[:token] = SecureRandom.urlsafe_base64
    end while ContactFile.exists?(:token => self[:token])
  end
  
  
  
end
