Module: Nylas::FileUtils

Defined in:
lib/nylas/utils/file_utils.rb

Overview

A collection of file-related utilities.

Constant Summary collapse

FORM_DATA_ATTACHMENT_SIZE =

The maximum size of an attachment that can be sent using json

3 * 1024 * 1024

Class Method Summary collapse

Class Method Details

.attach_file_request_builder(file_path) ⇒ Hash

Build the request to attach a file to a message/draft object.

Parameters:

  • file_path (String)

    The path to the file to attach.

Returns:

  • (Hash)

    The request that will attach the file to the message/draft



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/nylas/utils/file_utils.rb', line 42

def self.attach_file_request_builder(file_path)
  filename = File.basename(file_path)
  content_type = MIME::Types.type_for(file_path)
  content_type = if !content_type.nil? && !content_type.empty?
                   content_type.first.to_s
                 else
                   "application/octet-stream"
                 end
  size = File.size(file_path)
  content = File.new(file_path, "rb")

  {
    filename: filename,
    content_type: content_type,
    size: size,
    content: content
  }
end