Fix large attachment handling with string keys and custom content_ids#537
Merged
Fix large attachment handling with string keys and custom content_ids#537
Conversation
This fixes two bugs that caused attachments over 3MB (e.g., 5.4MB) to fail with "sending a json request as multipart/form-data" errors: 1. Size calculation only checked symbol keys (`:size`) but users may pass attachment hashes with string keys (`"size"`). This caused large files to be incorrectly sent as JSON instead of multipart form-data. 2. The `file_upload?` detection only matched keys like `file0`, `file1`, but users can specify custom `content_id` values. This caused multipart detection to fail for attachments with custom content IDs. Fixes: - Support both string and symbol keys when calculating attachment size - Detect attachments by checking for singleton methods (original_filename, content_type) rather than key name patterns
- Add empty line after guard clause in http_client.rb - Remove extra spacing in file_utils_spec.rb comments - Shorten test description to fit line length limit
…lity - HTTP client: support streaming attachments and file-like values - Add send_streaming_attachments_example - Fix Rubocop offenses (style, layout, gemspec order) - Replace CGI.parse with URI.decode_www_form for Ruby 3.4+ compatibility
- Modify .rubocop.yml to disable new cops and add specific RSpec rules - Update rubocop-rspec dependency version in gem_config.rb to ~> 3.5
agtang96
approved these changes
Feb 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes two bugs that caused attachments over 3MB (e.g., 5.4MB files) to fail with errors suggesting "sending a JSON request as multipart/form-data":
"size"instead of:size), the size was calculated as 0, causing large files to be incorrectly sent as JSON instead of multipart form-datafile_upload?method only matched keys likefile0,file1but users can specify customcontent_idvalues (e.g.,"my-inline-image"), causing multipart detection to failChanges
lib/nylas/utils/file_utils.rbfile_pathinbuild_form_requestlib/nylas/handler/http_client.rboriginal_filename,content_type) rather than key name patterns, supporting customcontent_idvaluesTest plan
file_utils_spec.rbhttp_client_spec.rb