fix(email-resend): support path and preserve base64 content in mapAttachments#16094
fix(email-resend): support path and preserve base64 content in mapAttachments#16094guoyangzhen 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
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
|
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.
|
Hi @DanRibbens, I've pushed a fix for the TS2322 type error. The return type of |
|
Hi @DanRibbens, I've pushed a fix for the TS2322 type error (commit 9b9ee99). The return type of is now explicitly typed as . Could you take another look when you get a chance? Thanks! |
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