Skip to main content

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 add @strapi/provider-upload-cloudinary

配置

🌐 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/uploadStreamdelete可用的选项。
/config/plugins.js
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: {},
},
},
},
// ...
});
Notes
  • Strapi 有一个默认的 security 中间件,它有一个非常严格的 contentSecurityPolicy,只允许加载 "'self'" 的图片和媒体。有关更多信息,请参见 provider page 上的示例配置或 中间件文档
  • 在每个环境使用不同的提供者时,请在 /config/env/${yourEnvironment}/plugins.js|ts 中指定正确的配置(参见 environments)。