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



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/nylas/utils/file_utils.rb', line 82

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