# 本地上传提供商

> Source: https://strapi.nodejs.cn/cms/configurations/media-library-providers/local-upload

🌐 Local Upload provider

`@strapi/provider-upload-local` 包允许你将媒体库资源存储在本地服务器文件系统上。本页涵盖安装和配置，包括可选的 `sizeLimit` 参数，用于控制最大上传文件大小。

🌐 The `@strapi/provider-upload-local` package lets you store Media Library assets on the local server file system. This page covers installation and configuration, including the optional `sizeLimit` parameter to control the maximum upload file size.

[媒体库](/cms/features/media-library) 功能由一个名为 Upload 的后端服务器包提供支持，该包利用了提供程序的使用。

🌐 The [Media Library](/cms/features/media-library) feature is powered by a back-end server package called Upload which leverages the use of providers.

Strapi 为媒体库维护了 3 个提供者。本页介绍本地上传提供者的安装和配置。有关其他提供者，请参阅 [媒体库页面](/cms/features/media-library#providers) 中的列表。

🌐 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](/cms/features/media-library#providers).

## 安装 {#installation}

🌐 Installation

要安装提供程序，请在终端中运行以下命令：

🌐 To install the provider, run the following command in a terminal:

```bash
yarn add @strapi/provider-upload-local
```

```bash
npm install @strapi/provider-upload-local --save
```

## 配置 {#configuration}

🌐 Configuration

提供者配置在 [ `/config/plugins` 文件](/cms/configurations/plugins) 中定义。如果此文件不存在，请先创建它。提供者配置接受以下条目：

🌐 Providers configuration is defined in [the `/config/plugins` file](/cms/configurations/plugins). If this file does not exist, create it first. The provider configuration accepts the following entries:

* `provider` 用于定义提供者名称（即 `local`）
* `providerOptions` 用于定义在构建提供者时传递的选项。

对于本地上传提供程序，`providerOptions` 只接受一个参数：`sizeLimit`，该参数必须是数字。单位是字节，默认值为 1000000000（1 GB）。在增加此限制时，还需配置 `maxFileSize` 请求体解析中间件，以便文件可以被发送和处理（详细信息请参见 [媒体库文档](/cms/features/media-library#max-file-size)）。

🌐 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 1000000000 (1 GB). When increasing this limit, also configure the body parser middleware `maxFileSize` so the file can be sent and processed (see [Media Library documentation](/cms/features/media-library#max-file-size) for details).

以下是配置示例：

🌐 The following is an example configuration:

```js title="/config/plugins.js"

module.exports = ({ env }) => ({
  // ...
  upload: {
    config: {
      provider: 'local',
      providerOptions: {
        sizeLimit: 100000,
      },
    },
  },
  // ...
});
```

```ts title="/config/plugins.ts"

  // ...
  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`.
