payloadcms/payload · error · APIError
Attachment is missing filename
Error message
Attachment is missing filename
What it means
Thrown by mapAttachments in the Resend adapter when an attachment object is missing the required `filename` field. Resend's API requires a filename for every attachment, so the adapter validates this before building the request rather than letting Resend reject the whole send.
Source
Thrown at packages/email-resend/src/index.ts:152
}
if (Array.isArray(addresses)) {
return addresses.map((address) => (typeof address === 'string' ? address : address.address))
}
return [addresses.address]
}
function mapAttachments(
attachments: SendEmailOptions['attachments'],
): ResendSendEmailOptions['attachments'] {
if (!attachments) {
return []
}
return attachments.map((attachment): Attachment => {
if (!attachment.filename) {
throw new APIError('Attachment is missing filename', 400)
}
if (!attachment.content && !attachment.path) {
throw new APIError('Attachment is missing both content and path', 400)
}
// When both content and path are provided, content takes priority; path is ignored.
if (attachment.path && !attachment.content) {
const path = typeof attachment.path === 'string' ? attachment.path : attachment.path.href
return {
filename: attachment.filename,
path,
}
}
if (typeof attachment.content === 'string') {
return {
content: attachment.content,View on GitHub (pinned to 00c58b35c0)
Solutions
- Ensure every attachment object includes a `filename` string (including extension).
- Default filename to a sensible value (e.g. originalname or 'attachment.bin') when the source object omits it.
- Validate the attachments array shape before calling payload.sendEmail.
Example fix
// before
attachments: [{ content: buf }]
// after
attachments: [{ filename: 'report.pdf', content: buf }] Defensive patterns
Strategy: validation
Validate before calling
function normalizeAttachments(attachments) {
return (attachments || []).map(a => {
if (!a.filename) throw new Error('Attachment is missing filename')
return a
})
} Type guard
const attachmentHasFilename = (a) => Boolean(a && a.filename)
Prevention
- Default filename to originalname (or 'attachment') when mapping uploads to attachments.
- Validate the attachments array shape before calling payload.sendEmail.
When it happens
Trigger: Calling payload.sendEmail with `attachments: [{ content: buffer }]` (no filename), or constructing attachments dynamically where the filename key is omitted/undefined.
Common situations: Building attachments from uploaded files and forgetting to map the original name to filename; renaming fields and missing one code path; attachments coming from a third-party payload that omits filename.
Related errors
- Attachment is missing both content and path
- Attachment content must be a string or a buffer
- Error sending email: ${statusCode}
- Username or email is required
- Email is required.
AI-assisted analysis of payloadcms/payload@00c58b35c0 (2026-08-12).
Data as JSON: /api/errors/72c65d2f9bc71758.
Report an issue: GitHub.