Skip to main content

Strapi 5 使用 koa-body v6

¥Strapi 5 uses koa-body v6

Strapi 5 使用 `koa-body`  v6,它将 formidable 更新为 v2。这意味着上传的文件具有新属性。

¥Strapi 5 uses `koa-body`  v6, which updates formidable to v2. This means uploaded files have new properties.

此页面是 重大变更数据库 的一部分,提供有关重大更改的信息以及从 Strapi v4 迁移到 Strapi 5 的其他说明。

¥This page is part of the breaking changes database 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

在 Strapi v4 中

¥In Strapi v4

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

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

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

在 Strapi 5 中

¥In Strapi 5

用户仍可能使用 ctx 对象创建自定义端点并处理文件,但属性名称不同:

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

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

迁移

¥Migration

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

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

注意

¥Notes

手动程序

¥Manual procedure

用户需要手动更新其自定义代码中使用的属性,参考官方 `koa-body` `formidable`  文档。

¥Users need to manually update the properties used in their custom code, referring to the official `koa-body`  and `formidable`  documentations.