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



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/nylas/utils/file_utils.rb', line 95

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,
    file_path: file_path
  }
end