Module: Chronicle::ETL::Utils::BinaryAttachments

Defined in:
lib/chronicle/etl/utils/binary_attachments.rb

Overview

Utility methods for dealing with binary files

Class Method Summary collapse

Class Method Details

.filename_to_base64(filename:, mimetype: nil) ⇒ Object



9
10
11
12
13
# File 'lib/chronicle/etl/utils/binary_attachments.rb', line 9

def self.filename_to_base64(filename:, mimetype: nil)
  mimetype ||= guess_mimetype(filename: filename)

  "data:#{mimetype};base64,#{Base64.strict_encode64(File.read(filename))}"
end

.guess_mimetype(filename:) ⇒ Object



15
16
17
# File 'lib/chronicle/etl/utils/binary_attachments.rb', line 15

def self.guess_mimetype(filename:)
  Marcel::MimeType.for(filename)
end