diff --git a/.changeset/smart-melons-shop.md b/.changeset/smart-melons-shop.md new file mode 100644 index 00000000000..e998cdef549 --- /dev/null +++ b/.changeset/smart-melons-shop.md @@ -0,0 +1,10 @@ +--- +"@logto/phrases": patch +"@logto/core": patch +--- + +Fix file upload API. + +The `koa-body` has been upgraded to the latest version, which caused the file upload API to break. This change fixes the issue. + +The `ctx.request.files.file` in the new version is an array, so the code has been updated to pick the first one. diff --git a/packages/core/src/routes/user-assets.ts b/packages/core/src/routes/user-assets.ts index 9eb0c054597..19c155bccb1 100644 --- a/packages/core/src/routes/user-assets.ts +++ b/packages/core/src/routes/user-assets.ts @@ -52,13 +52,15 @@ export default function userAssetsRoutes( '/user-assets', koaGuard({ files: object({ - file: uploadFileGuard, + file: uploadFileGuard.array().min(1), }), response: userAssetsGuard, }), async (ctx, next) => { - const { file } = ctx.guard.files; + const { file: bodyFiles } = ctx.guard.files; + const file = bodyFiles[0]; + assertThat(file, 'guard.invalid_input'); assertThat(file.size <= maxUploadFileSize, 'guard.file_size_exceeded'); assertThat( allowUploadMimeTypes.map(String).includes(file.mimetype),