本地上传提供者
🌐 Local Upload provider
Page summary:
@strapi/provider-upload-local包允许你将媒体库资源存储在本地服务器文件系统上。本页涵盖安装和配置,包括可选的sizeLimit参数,用于控制最大上传文件大小。🌐 The
@strapi/provider-upload-localpackage lets you store Media Library assets on the local server file system. This page covers installation and configuration, including the optionalsizeLimitparameter to control the maximum upload file size.
媒体库 功能由一个名为 Upload 的后端服务器包提供支持,该包利用了提供程序的使用。
🌐 The Media Library feature is powered by a back-end server package called Upload which leverages the use of providers.
Strapi 为媒体库维护了 3 个提供者。本页介绍本地上传提供者的安装和配置。有关其他提供者,请参阅 媒体库页面 中的列表。
🌐 Strapi maintains 3 providers for the Media Library. The present page is about the local Upload provider installation and configuration. For other providers, please refer to the list in the Media Library page.
安装
🌐 Installation
要安装提供程序,请在终端中运行以下命令:
🌐 To install the provider, run the following command in a terminal:
- Yarn
- NPM
yarn add @strapi/provider-upload-local
npm install @strapi/provider-upload-local --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用于定义提供者名称(即local)providerOptions用于定义在构建提供者时传递的选项。
对于本地上传提供程序,providerOptions 只接受一个参数:sizeLimit,它必须是数字。单位是字节,默认值为 1000000。增加此限制时,还需配置请求体解析中间件 maxFileSize,以便文件能够被发送和处理(详情请参见 媒体库文档)。
🌐 For the local Upload provider, providerOptions accepts only one parameter: sizeLimit, which must be a number. The unit is bytes, and the default value is 1000000. When increasing this limit, also configure the body parser middleware maxFileSize so the file can be sent and processed (see Media Library documentation for details).
以下是配置示例:
🌐 The following is an example configuration:
- JavaScript
- TypeScript
module.exports = ({ env }) => ({
// ...
upload: {
config: {
provider: 'local',
providerOptions: {
sizeLimit: 100000,
},
},
},
// ...
});
export default ({ env }) => ({
// ...
upload: {
config: {
provider: 'local',
providerOptions: {
sizeLimit: 100000,
},
},
},
// ...
});
与 AWS S3 和 Cloudinary 提供程序不同,本地上传提供程序不需要特殊的安全中间件配置。默认配置已经允许从 self 加载图片和媒体。
🌐 Unlike the AWS S3 and Cloudinary providers, the local Upload provider does not require special security middleware configuration. The default configuration already allows loading images and media from self.