Providers
Certain plugins can be extended via the installation and configuration of additional providers.
Providers add an extension to the core capabilities of the plugin, for example to upload media files to AWS S3 instead of the local server, or using Amazon SES for emails instead of Sendmail.
Only the Upload and Email plugins are currently designed to work with providers.
Upload
官方支援的plugin已有教學[[99. Upload(Media Library)#AWS S3]]
Creating providers
To implement your own custom provider you must create a Node.js module.
1. Create a package.json
file
- npm init
- 自動產生package.json並設定相關資訊
# package.json
{
"name": "test-module",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
2. Develop provider
export default {
init(providerOptions) {
// init your provider if necessary
return {
upload(file) {
// upload the file in the provider
// file content is accessible by `file.buffer`
},
uploadStream(file) {
// upload the file in the provider
// file content is accessible by `file.stream`
},
delete(file) {
// delete the file in the provider
},
};
},
};
- providerOptions that contains configurations written in plugins.js
- settings that contains configurations written in plugins.js
- options that contains options you send when you call the send function from the email plugin service
Example Provider
- AWS S3
- Local
3. npm install
- Create a
providers
folder under root application - Create your provider (e.g.
./providers/strapi-provider-upload-<provider>
) - Edit package.json under root application to link provider
{ ... "dependencies": { ... "strapi-provider-<plugin>-<provider>": "file:providers/strapi-provider-<plugin>-<provider>", ... } }
- Update your
./config/plugins.js
file to configure the provider. - run
yarn install
ornpm install
(TBC)