Skip to content

Commit

Permalink
feat(docs): add example for customising the filename of an upload via…
Browse files Browse the repository at this point in the history
… hooks (#9124)
  • Loading branch information
paulpopus authored Nov 12, 2024
1 parent 570c610 commit d839138
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions docs/upload/overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,23 @@ export default buildConfig({
})
```

### Custom filename via hooks

You can customize the filename before it's uploaded to the server by using a `beforeOperation` hook.

```ts
beforeOperation: [
({ req, operation }) => {
if ((operation === 'create' || operation === 'update') && req.file) {
req.file.name = 'test.jpg'
}
},
],
```

The `req.file` object will have additional information about the file, such as mimeType and extension, and you also have full access to the file data itself.
The filename from here will also be threaded to image sizes if they're enabled.

## Image Sizes

If you specify an array of `imageSizes` to your `upload` config, Payload will automatically crop and resize your uploads to fit each of the sizes specified by your config.
Expand Down

0 comments on commit d839138

Please sign in to comment.