-
Notifications
You must be signed in to change notification settings - Fork 3k
docs: batch docs issues #13823
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
Open
zubricks
wants to merge
7
commits into
main
Choose a base branch
from
docs/batch-docs-issues
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
docs: batch docs issues #13823
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9386e67
updates dockerfile example in production docs
zubricks 8cc630f
updates documentation to include how to send email with attachments f…
zubricks 0d90edc
updates docs for unique option on select field
zubricks 5ace5e8
- Updates node version in Dockerfile example in production
zubricks 6e7f509
adds ts to code snippets for correct highlighting
zubricks 8f06d2e
updates both references to node version to 22-alpine
zubricks 38d3efb
updates code snippet in uploads
zubricks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,6 +158,77 @@ const email = await payload.sendEmail({ | |
}) | ||
``` | ||
|
||
## Sending email with attachments | ||
|
||
**Nodemailer adapter (SMTP/SendGrid/etc.)** | ||
|
||
Works with `@payloadcms/email-nodemailer` and any Nodemailer transport. | ||
|
||
```ts | ||
await payload.sendEmail({ | ||
to: '[email protected]', | ||
subject: 'Your report', | ||
html: '<p>See attached.</p>', | ||
attachments: [ | ||
// From a file path (local disk, mounted volume, etc.) | ||
{ | ||
filename: 'invoice.pdf', | ||
path: '/var/data/invoice.pdf', | ||
contentType: 'application/pdf', | ||
}, | ||
// From a Buffer you generated at runtime | ||
{ | ||
filename: 'report.csv', | ||
content: Buffer.from('col1,col2\nA,B\n'), | ||
contentType: 'text/csv', | ||
}, | ||
], | ||
}) | ||
``` | ||
|
||
Anything supported by Nodemailer’s attachments—streams, Buffers, URLs, content IDs for inline images (cid), etc.—will work here. | ||
|
||
**Resend adapter** | ||
|
||
Works with @payloadcms/email-resend. | ||
|
||
For attachments from remote URLs | ||
|
||
```ts | ||
await payload.sendEmail({ | ||
to: '[email protected]', | ||
subject: 'Your invoice', | ||
html: '<p>Thanks! Invoice attached.</p>', | ||
attachments: [ | ||
{ | ||
// Resend will fetch this URL | ||
path: 'https://example.com/invoices/1234.pdf', | ||
filename: 'invoice-1234.pdf', | ||
}, | ||
], | ||
}) | ||
``` | ||
|
||
For a local file | ||
|
||
```ts | ||
import { readFile } from 'node:fs/promises' | ||
|
||
const pdf = await readFile('/var/data/invoice.pdf') | ||
await payload.sendEmail({ | ||
to: '[email protected]', | ||
subject: 'Your invoice', | ||
html: '<p>Thanks! Invoice attached.</p>', | ||
attachments: [ | ||
{ | ||
filename: 'invoice.pdf', | ||
// Resend expects Base64 here | ||
content: pdf.toString('base64'), | ||
}, | ||
], | ||
}) | ||
``` | ||
|
||
## Using multiple mail providers | ||
|
||
Payload supports the use of a single transporter of email, but there is nothing stopping you from having more. Consider a use case where sending bulk email is handled differently than transactional email and could be done using a [hook](/docs/hooks/overview). |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -305,6 +305,53 @@ export const Media: CollectionConfig = { | |
} | ||
``` | ||
|
||
3. Dynamic thumbnails via hooks | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why would you use this method over the 2nd method? That should be explained in the docs if there is a good reason. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #11453 |
||
|
||
```ts | ||
import type { CollectionConfig, AfterChangeHook, AfterReadHook } from 'payload' | ||
|
||
// Example helper that builds a CDN URL (your logic here) | ||
const buildThumbURL = ({ filename }: { filename?: string }) => | ||
filename ? `https://cdn.example.com/thumbs/${filename}.jpg` : undefined | ||
|
||
const setThumbURL: AfterChangeHook = async ({ doc, operation }) => { | ||
// compute a thumbnail URL (first frame, resized, etc.) | ||
const thumbnailURL = buildThumbURL({ filename: doc?.filename }) | ||
// persist to the same doc so the Admin can reuse it | ||
return { ...doc, thumbnailURL } | ||
} | ||
|
||
const exposeThumbURL: AfterReadHook = async ({ doc }) => { | ||
// ensure the field is always present on reads | ||
return { | ||
...doc, | ||
thumbnailURL: | ||
doc.thumbnailURL ?? buildThumbURL({ filename: doc?.filename }), | ||
} | ||
} | ||
|
||
export const Media: CollectionConfig = { | ||
slug: 'media', | ||
upload: true, | ||
admin: { | ||
// Use the field value for the Admin thumbnail | ||
adminThumbnail: ({ doc }) => doc?.thumbnailURL, | ||
}, | ||
hooks: { | ||
afterChange: [setThumbURL], | ||
afterRead: [exposeThumbURL], | ||
}, | ||
fields: [ | ||
// store the dynamic URL (hidden from editors if you like) | ||
{ | ||
name: 'thumbnailURL', | ||
type: 'text', | ||
admin: { hidden: true }, | ||
}, | ||
], | ||
} | ||
``` | ||
|
||
## Restricted File Types | ||
|
||
Possibly problematic file types are automatically restricted from being uploaded to your application. | ||
|
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we discussing
array
andblock
field limitations inside of the select field docs page?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this update was meant to provide clarity regarding this: #12836