You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Trying to rename a file before it's uploaded to S3, and using the uuid that's generated in id is perfect, except there's no way to get it from the req, data, originalDoc params. So far I have this, but it generates a distinct ID:
import { type CollectionBeforeChangeHook } from 'payload'
import { generateId } from '@/lib/id'
/**
* A hook that generates a unique ID as the filename for file uploads.
* This ensures unique filenames and prevents collisions in cloud storage.
*/
export const useIdAsFilename: CollectionBeforeChangeHook = ({ operation, data }) => {
if (operation === 'create') {
data.filename = generateId()
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Trying to rename a file before it's uploaded to S3, and using the uuid that's generated in
id
is perfect, except there's no way to get it from the req, data, originalDoc params. So far I have this, but it generates a distinct ID:Is it possible to use the generated
id
field?Beta Was this translation helpful? Give feedback.
All reactions