媒体库提供商
🌐 Media Library providers
媒体库 功能由一个名为 Upload 的后端服务器包提供支持,该包利用了提供程序的使用。
🌐 The Media Library feature is powered by a back-end server package called Upload which leverages the use of providers.
默认情况下,Strapi 提供了一个提供程序,可以将文件上传到 Strapi 项目中的本地 public/uploads/ 目录。还可以使用其他提供程序,这些提供程序为插件的核心功能添加了扩展。使用它们可以将文件上传到其他位置,例如 AWS S3 或 Cloudinary。
🌐 By default Strapi provides a provider that uploads files to a local public/uploads/ directory in your Strapi project. Additional providers are available and add an extension to the core capabilities of the plugin. Use them to upload your files to another location, such as AWS S3 or Cloudinary.
Strapi 维护官方提供者,可通过 Marketplace 发现。社区维护的提供者也可以通过 npm 获取。
可以将提供者配置为私有,以确保资源 URL 会被签名以实现安全访问。
🌐 A provider can be configured to be private to ensure asset URLs will be signed for secure access.
安装提供程序
🌐 Installing providers
可以使用 NPM 或 Yarn 安装新提供者,使用以下格式 @strapi/provider-<plugin>-<provider> --save。
例如,要为媒体库功能安装 AWS S3 提供程序:
🌐 For example, to install the AWS S3 provider for the Media Library feature:
- Yarn
- NPM
yarn add @strapi/provider-upload-aws-s3
npm install @strapi/provider-upload-aws-s3 --save
配置提供者
🌐 Configuring providers
新安装的提供程序已在 “/config/plugins” 文件 中启用并配置。如果该文件不存在,请先创建它。
🌐 Newly installed providers are enabled and configured in the /config/plugins file. If this file does not exist, create it first.
每个提供者将有不同的配置设置可用。请查看下方 Strapi 维护的提供者的专用页面中该提供者的相关条目,或在提供者的 Marketplace 页面上查看。
Strapi 维护的提供者如下。点击卡片将重定向到带有配置示例的文档页面:
🌐 The providers maintained by Strapi are the following. Clicking on a card will redirect you to a docs page with a configuration example:
- Strapi 有一个默认的
security中间件,它有一个非常严格的contentSecurityPolicy,只允许加载"'self'"的图片和媒体。有关更多信息,请参见 provider page 上的示例配置或 中间件文档。 - 在每个环境使用不同的提供者时,请在
/config/env/${yourEnvironment}/plugins.js|ts中指定正确的配置(参见 environments)。