Skip to content

Commit

Permalink
Allow custom filename when adding an attachment
Browse files Browse the repository at this point in the history
  • Loading branch information
loomchild committed Oct 16, 2024
1 parent d2f07ed commit 113da09
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/nylas/utils/file_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ def self.handle_message_payload(request_body)
# Build the request to attach a file to a message/draft object.
# @param file_path [String] The path to the file to attach.
# @return [Hash] The request that will attach the file to the message/draft
def self.attach_file_request_builder(file_path)
filename = File.basename(file_path)
def self.attach_file_request_builder(file_path, filename = nil)
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
Expand Down
15 changes: 15 additions & 0 deletions spec/nylas/utils/file_utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@
file_path: file_path
)
end

it "accepts optional filename parameter" do
file_path = "/path/to/file.txt"
filename = "customm-file.txt"

attach_file_req = described_class.attach_file_request_builder(file_path, filename)

expect(attach_file_req).to eq(
filename: "customm-file.txt",
content_type: "text/plain",
size: 100,
content: mock_file,
file_path: file_path
)
end
end

describe "#build_form_request" do
Expand Down

0 comments on commit 113da09

Please sign in to comment.