Skip to content

Add callout about overriding image function in Plugins extension docs #2601

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
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docusaurus/docs/cms/features/media-library.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ When using the default upload provider, the following specific configuration opt
The Upload request timeout is defined in the server options, not in the Upload plugin options, as it's not specific to the Upload plugin but is applied to the whole Strapi server instance (see [upload request timeout](#upload-request-timeout)).
:::

:::note
If you wish to override the image function to generate custom file names, please refer to the [Plugins extension](/cms/plugins-development/plugins-extension#within-the-extensions-folder) documentation.
:::

#### Example custom configuration

The following is an example of a custom configuration for the Upload plugin when using the default upload provider:
Expand Down
22 changes: 22 additions & 0 deletions docusaurus/docs/cms/plugins-development/plugins-extension.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,28 @@ module.exports = (plugin) => {
```
</details>

:::note
The `strapi-server.js|ts` file is also where you can override the image function, by replacing the Upload plugin's `generateFileName()` function so that it generates custom image names.

<details>
<summary>Example of custom file-naming logic</summary>

```js title="./src/extensions/upload/strapi-server.js|ts"

module.exports = (plugin) => {
plugin.services.upload.image.generateFileName = (file) => {
// Example: prefix a timestamp before the original name
return `${Date.now()}_${file.hash}${file.ext}`;
};

return plugin;
};

```
</details>

:::

### Within the register and bootstrap functions

To extend a plugin's interface within `./src/index.js|ts`, use the `bootstrap()` and `register()` [functions](/cms/configurations/functions) of the whole project, and access the interface programmatically with [getters](/cms/plugins-development/server-api#usage).
Expand Down
22 changes: 22 additions & 0 deletions docusaurus/static/llms-full.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10545,6 +10545,28 @@ module.exports = (plugin) => {
```
</details>

:::note
The `strapi-server.js|ts` file is also where you can override the image function, by replacing the Upload plugin's `generateFileName()` function so that it generates custom image names.

<details>
<summary>Example of custom file-naming logic</summary>

```js title="./src/extensions/upload/strapi-server.js|ts"

module.exports = (plugin) => {
plugin.services.upload.image.generateFileName = (file) => {
// Example: prefix a timestamp before the original name
return `${Date.now()}_${file.hash}${file.ext}`;
};

return plugin;
};

```
</details>

:::

### Within the register and bootstrap functions

To extend a plugin's interface within `./src/index.js|ts`, use the `bootstrap()` and `register()` [functions](/cms/configurations/functions) of the whole project, and access the interface programmatically with [getters](/cms/plugins-development/server-api#usage).
Expand Down