fix(email-resend): support path and preserve base64 content in mapAttachments#16094
Open
guoyangzhen wants to merge 2 commits intopayloadcms:mainfrom
Open
fix(email-resend): support path and preserve base64 content in mapAttachments#16094guoyangzhen wants to merge 2 commits intopayloadcms:mainfrom
guoyangzhen wants to merge 2 commits intopayloadcms:mainfrom
Conversation
…achments Fixes two bugs in mapAttachments that caused all email attachments to corrupt or fail: 1. path support: Forward the 'path' property when 'content' is absent, allowing cloud-hosted attachments per Payload docs. 2. Base64 preservation: Keep string content as-is instead of wrapping in Buffer.from(), since Resend's REST API expects base64 strings and JSON.stringify would corrupt Buffer objects. Fixes payloadcms#16093
DanRibbens
requested changes
Mar 30, 2026
Contributor
DanRibbens
left a comment
There was a problem hiding this comment.
This doesn't currently build. See type error in CI checks https://github.com/payloadcms/payload/pull/16094/checks
Author
|
Thanks for the review feedback! The TS2322 type error is because the mapped objects have inferred literal types that don't match The fix is to explicitly type the return in Proposed fix: Return return attachments.map((attachment): Attachment => {
// ... existing logic unchanged
}) as Attachment[] |
The Attachment type has filename?: false | string | undefined which causes union type inference issues. Adding explicit return type annotation (: Attachment) ensures each branch conforms to the expected type.
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.
Fixes #16093
Problem
The
mapAttachmentsfunction in@payloadcms/email-resendhas two bugs:Bug 1:
pathis not supportedThe function requires
contentto exist and throws if it is missing, but the Payload docs recommend usingpathfor cloud storage attachments. Thepathproperty exists in theAttachmenttype but is never forwarded.Bug 2: Base64 content produces corrupt files
When
contentis a string (base64), the code wraps it inBuffer.from(attachment.content). Since Resend usesJSON.stringify()to serialize the request body, this Buffer becomes{"type":"Buffer","data":[...]}instead of the expected base64 string. The attachment arrives corrupt.Fix
pathas an alternative tocontent— forward it directly when content is absent