lib/nylas/utils/file_utils.rb in nylas-6.2.1 vs lib/nylas/utils/file_utils.rb in nylas-6.2.2
- old
+ new
@@ -34,11 +34,20 @@
end
file = File.open(attachment[:file_path], "rb")
end
- form_data.merge!({ "file#{index}" => file })
+ # Setting original filename and content type if available. See rest-client#lib/restclient/payload.rb
+ filename = attachment[:filename] || attachment["filename"]
+ file.define_singleton_method(:original_filename) { filename } if filename
+
+ content_type = attachment[:content_type] || attachment["content_type"]
+ file.define_singleton_method(:content_type) { content_type } if content_type
+
+ content_id = attachment[:content_id] || attachment["content_id"] || "file#{index}"
+
+ form_data.merge!({ content_id => file })
opened_files << file
end
form_data.merge!({ "multipart" => true, "message" => message_payload })
@@ -91,25 +100,25 @@
# Build the request to attach a file to a message/draft object.
# @param file_path [String] The path to the file to attach.
# @param filename [String] The name of the attached file. Optional, derived from file_path by default.
# @return [Hash] The request that will attach the file to the message/draft
- def self.attach_file_request_builder(file_path, filename = nil)
+ def self.attach_file_request_builder(file_path, filename = nil, content_id = 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
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,
+ content_id: content_id,
file_path: file_path
}
end
end
end