Skip to content

Commit 8c65f6a

Browse files
author
Subash Pradhan
committed
Add ability to send inline image > 3mb
1 parent 9d6db9e commit 8c65f6a

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

lib/nylas/utils/file_utils.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ def self.build_form_request(request_body)
4343
content_type = attachment[:content_type] || attachment["content_type"]
4444
file.define_singleton_method(:content_type) { content_type } if content_type
4545

46-
form_data.merge!({ "file#{index}" => file })
46+
content_id = attachment[:content_id] || attachment["content_id"] || "file#{index}"
47+
48+
form_data.merge!({ content_id => file })
4749
opened_files << file
4850
end
4951

@@ -100,7 +102,7 @@ def self.handle_message_payload(request_body)
100102
# @param file_path [String] The path to the file to attach.
101103
# @param filename [String] The name of the attached file. Optional, derived from file_path by default.
102104
# @return [Hash] The request that will attach the file to the message/draft
103-
def self.attach_file_request_builder(file_path, filename = nil)
105+
def self.attach_file_request_builder(file_path, filename = nil, content_id = nil)
104106
filename ||= File.basename(file_path)
105107
content_type = MIME::Types.type_for(file_path)
106108
content_type = if !content_type.nil? && !content_type.empty?
@@ -110,12 +112,12 @@ def self.attach_file_request_builder(file_path, filename = nil)
110112
end
111113
size = File.size(file_path)
112114
content = File.new(file_path, "rb")
113-
114115
{
115116
filename: filename,
116117
content_type: content_type,
117118
size: size,
118119
content: content,
120+
content_id: content_id,
119121
file_path: file_path
120122
}
121123
end

spec/nylas/utils/file_utils_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
content_type: "text/plain",
2323
size: 100,
2424
content: mock_file,
25+
content_id: nil,
2526
file_path: file_path
2627
)
2728
end
@@ -39,6 +40,7 @@
3940
content_type: "application/octet-stream",
4041
size: file_size,
4142
content: mock_file,
43+
content_id: nil,
4244
file_path: file_path
4345
)
4446
end
@@ -54,6 +56,23 @@
5456
content_type: "text/plain",
5557
size: 100,
5658
content: mock_file,
59+
content_id: nil,
60+
file_path: file_path
61+
)
62+
end
63+
64+
it "accepts optional content_id parameter" do
65+
file_path = "/path/to/file.txt"
66+
content_id = "content-id-123"
67+
68+
attach_file_req = described_class.attach_file_request_builder(file_path, nil, content_id)
69+
70+
expect(attach_file_req).to eq(
71+
filename: "file.txt",
72+
content_type: "text/plain",
73+
size: 100,
74+
content: mock_file,
75+
content_id: content_id,
5776
file_path: file_path
5877
)
5978
end

0 commit comments

Comments
 (0)