class Obra::AnexoDaFiscalizacao < ApplicationRecord
	has_paper_trail

	belongs_to :foto_da_fiscalizacao, class_name: 'Obra::FotoDaFiscalizacao'

	has_attached_file :file, styles: { thumb: "100x100>" }

	validates_attachment_content_type :file, content_type: ['application/pdf', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'image/gif', 'image/jpg', 'image/jpeg', 'image/png', 'image/bmp']
	validates_attachment_size :file, in: 0..10.megabytes


	def gerar_imagem_em_base64(tamanho=:thumb)
		file_contents = open(file.path(tamanho)) { |f| f.read }
		return 'data:' + file.content_type + ';base64,' + Base64.strict_encode64(file_contents)
	end

end
