Skip to content

fix: treat an empty @UploadedFiles array as missing when the parameter is required - #1557

Open
suresh-saini wants to merge 1 commit into
typestack:developfrom
gcsns:fix/required-uploaded-files-empty-array
Open

suresh-saini wants to merge 1 commit into
typestack:developfrom
gcsns:fix/required-uploaded-files-empty-array

Conversation

@suresh-saini

@suresh-saini suresh-saini commented Oct 7, 2026 •

Copy link
Copy Markdown

Description

@UploadedFiles('photos', { required: true }) does not reject a multipart request that carries other fields but no file. multer sets req.files = [] for a parsed multipart body, and the generic required check in ActionParameterHandler.handleValue only treats null, undefined and '' as empty, so the empty array passes and the action runs with no files. @UploadedFile is not affected because req.file stays undefined.

This adds an explicit branch for files parameters that also treats an empty array as missing, raising the same ParamRequiredError as every other required parameter.

Checklist

  • Added a functional test (@UploadedFiles when required is used a multipart request with other fields but no file is a bad request), which fails on develop (500 → expected 400) and passes with the fix
  • npm run prettier:check, npm run lint:check (the one pre-existing lint error on this file is untouched), npm test for action-params.spec.ts

Observed on routing-controllers 0.11.3 with Express.

…r is required

A multipart request that carries other fields but no file reaches the handler as an empty array
(multer sets req.files = []), not as undefined, so the required check let it through and the action
ran with no files. An absent @uploadedfile was already rejected because req.file stays undefined.
@suresh-saini
suresh-saini force-pushed the fix/required-uploaded-files-empty-array branch from b43f0ad to ad22256 Compare October 7, 2026 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant