Cloudinary 提供商
🌐 Cloudinary provider
Page summary:
@strapi/provider-upload-cloudinary包允许你将媒体库资源存储在 Cloudinary 上。本页介绍使用你的 Cloudinary 云名称、API 密钥和 API 密码进行的安装和配置。
媒体库 功能由一个名为 Upload 的后端服务器包提供支持,该包利用了提供程序的使用。
🌐 The Media Library feature is powered by a back-end server package called Upload which leverages the use of providers.
Strapi 为媒体库维护了 3 个提供者。本页介绍 Cloudinary 提供者的安装和配置。有关其他提供者,请参阅 媒体库页面 中的列表。
安装
🌐 Installation
要安装官方 Strapi 维护的 Cloudinary 提供程序,请在终端中运行以下命令:
🌐 To install the official Strapi-maintained Cloudinary provider, run the following command in a terminal:
- Yarn
- NPM
yarn add @strapi/provider-upload-cloudinary
npm install @strapi/provider-upload-cloudinary --save
配置
🌐 Configuration
提供者配置在 /config/plugins 文件 中定义。如果此文件不存在,请先创建它。提供者配 置接受以下条目:
🌐 Providers configuration is defined in the /config/plugins file. If this file does not exist, create it first. The provider configuration accepts the following entries:
provider用于定义提供者名称(即cloudinary)providerOptions用于定义在构建提供者期间传递的选项(完整选项列表见 Cloudinary documentation )actionOptions用于定义直接传递给每个方法参数的选项。官方的 Cloudinary 文档列出了 upload/uploadStream 和 delete可用的选项。
- JavaScript
- TypeScript
module.exports = ({ env }) => ({
// ...
upload: {
config: {
provider: 'cloudinary',
providerOptions: {
cloud_name: env('CLOUDINARY_NAME'),
api_key: env('CLOUDINARY_KEY'),
api_secret: env('CLOUDINARY_SECRET'),
},
actionOptions: {
upload: {},
uploadStream: {},
delete: {},
},
},
},
// ...
});
export default ({ env }) => ({
// ...
upload: {
config: {
provider: 'cloudinary',
providerOptions: {
cloud_name: env('CLOUDINARY_NAME'),
api_key: env('CLOUDINARY_KEY'),
api_secret: env('CLOUDINARY_SECRET'),
},
actionOptions: {
upload: {},
uploadStream: {},
delete: {},
},
},
},
// ...
});
- Strapi 有一个默认的
security中间件,它有一个非常严格的contentSecurityPolicy,只允许加载"'self'"的图片和媒体。有关更多信息,请参见 provider page 上的示例配置或 中间件文档。 - 在每个环境使用不同的提供者时,请在
/config/env/${yourEnvironment}/plugins.js|ts中指定正确的配置(参见 environments)。