# Strapi 5 使用 koa-body v6

> Source: https://strapi.nodejs.cn/cms/migration/v4-to-v5/breaking-changes/koa-body-v6

🌐 Strapi 5 uses `koa-body` v6

Strapi 5 升级到 `koa-body` v6，配合 `formidable` v2，在自定义端点中将上传文件的属性从 `path`、`name`、`type` 改为 `filepath`、`originalFilename`、`mimetype`。

🌐 Strapi 5 upgrades to `koa-body` v6 with `formidable` v2, changing uploaded file properties from `path`, `name`, `type` to `filepath`, `originalFilename`, `mimetype` in custom endpoints.

Strapi 5 使用 [`koa-body`](https://github.com/koajs/koa-body) v6，这将 `formidable` 更新到 v2。这意味着上传的文件具有新的属性。

🌐 Strapi 5 uses [`koa-body`](https://github.com/koajs/koa-body) v6, which updates `formidable` to v2. This means uploaded files have new properties.

此页面是[重大更改数据库](/cms/migration/v4-to-v5/breaking-changes)的一部分，提供关于重大更改的信息以及从 Strapi v4 迁移到 Strapi 5 的附加说明。

🌐 This page is part of the [breaking changes database](/cms/migration/v4-to-v5/breaking-changes) and provides information about the breaking change and additional instructions to migrate from Strapi v4 to Strapi 5.

- Is this breaking change affecting plugins? Yes
- Is this breaking change automatically handled by a codemod? No

## 重大变更描述 {#breaking-change-description}

🌐 Breaking change description

**在 Strapi v4 中**

用户可能会创建自定义端点并使用 `ctx` 对象处理文件：

🌐 A user might create custom endpoints and handle files with the `ctx` object:

  ```js
  const endpoint = (ctx) => {
      ctx.request.files.fileName.path
      ctx.request.files.fileName.name
      ctx.request.files.fileName.type
  }
  ```

**在 Strapi 5 中**

用户仍然可以使用 `ctx` 对象创建自定义端点并处理文件，但属性名称有所不同：

🌐 A user might still create custom endpoints and handle files with the `ctx` object, but the property names are different:

  ```js
  const endpoint = (ctx) => {
    ctx.request.files.fileName.filepath
    ctx.request.files.fileName.originalFilename
    ctx.request.files.fileName.mimetype
  }
  ```

## 迁移 {#migration}

🌐 Migration

本节重新组合了有关引入的重大更改的有用说明和程序。

🌐 This section regroups useful notes and procedures about the introduced breaking change.

### 注意 {#notes}

🌐 Notes

- 官方 [`koa-body`](https://github.com/koajs/koa-body/blob/master/CHANGELOG.md) 文档列出了变更。
- 官方 [`formidable`](https://github.com/node-formidable/formidable/blob/master/CHANGELOG.md#200) 文档列出了更改。

### 手动操作 {#manual-procedure}

🌐 Manual procedure

用户需要手动更新他们自定义代码中使用的属性，可参考官方 [`koa-body`](https://github.com/koajs/koa-body) 和 [`formidable`](https://github.com/node-formidable/formidable) 文档。

🌐 Users need to manually update the properties used in their custom code, referring to the official [`koa-body`](https://github.com/koajs/koa-body) and [`formidable`](https://github.com/node-formidable/formidable) documentations.
