Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set multipart/form-data header while sending attachments > 3mb #486

Open
byteg opened this issue Aug 28, 2024 · 2 comments
Open

Set multipart/form-data header while sending attachments > 3mb #486

byteg opened this issue Aug 28, 2024 · 2 comments
Labels

Comments

@byteg
Copy link

byteg commented Aug 28, 2024

Describe the bug
"Content-Type": "multipart/form-data" is not set when I try to send attachments > 3mb.

To Reproduce
Some steps involved to reproduce the bug and any code samples you can share.

request_body = {
  subject: "send large attachments",
  body: "large attachments",
  attachments: [
    {  content: "<large content here>", content_type: "", size: SIZE, filename: "filename"}
  ],
  to: [{email: "[email protected]"}]
}
response, _request_id = nylas.messages.send(identifier:, request_body:)

I get an error:
Nylas::NylasApiError (request must be of content-type multipart/form-data or application/json):
Expected behavior
Large attachments are sent correctly

SDK Version:
nylas (6.1.1)

Additional context
Update: IT DOES NOT HELP
Possible fix:
https://github.com/nylas/nylas-ruby/blob/main/lib/nylas/handler/http_client.rb#L101
Add line:
resulting_headers["Content-type"] = "multipart/form-data"

@byteg byteg added the bug label Aug 28, 2024
@mrashed-dev
Copy link
Contributor

Hey @byteg! Thanks for opening this issue. Can I ask what the type of object is getting sent?

@maxmetcalf12
Copy link

maxmetcalf12 commented Nov 13, 2024

I think the solution here is to send the attachment as a Nylas file object if it is >3mb. I have the following code that is working for me.

if attachment.blob.byte_size > 3.megabytes
  Nylas::FileUtils.attach_file_request_builder(file_path, name)
else
  {
    content: base64_content,
    content_type: attachment.content_type,
    filename: name,
  }
end

-- UPDATE --
Looking deeper into it, I think you can just use Nylas::FileUtils.attach_file_request_builder for all requests and it should handle them (as of 6.1.1). The one bug here is you lose filename if the attachment is >3MB, but that's probably a separate bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants