Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pipe validation for @UploadFiles() not working #13532

Open
4 of 15 tasks
shreyas-segu opened this issue May 3, 2024 · 1 comment
Open
4 of 15 tasks

Pipe validation for @UploadFiles() not working #13532

shreyas-segu opened this issue May 3, 2024 · 1 comment
Labels
needs triage This issue has not been looked into

Comments

@shreyas-segu
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

The pipe validation for the @UploadFiles annotation is not working, whereas the @UploadFile() annotation is working as expected

Minimum reproduction code

https://github.com/shreyas-segu/multiple-files-upload-validation-bug

Steps to reproduce

  1. npm ci
  2. npm run start
  3. use the request.txt to execute the curl request which is not working as expected, use the SamplePNGImage_100kbmb.png for the sample file
  4. use the request-working.txt for the curl request which is working, you can use the same file

Expected behavior

The multiple files upload endpoint with the pipe validation should not throw any validation errors.

Package

  • I don't know. Or some 3rd-party package
  • @nestjs/common
  • @nestjs/core
  • @nestjs/microservices
  • @nestjs/platform-express
  • @nestjs/platform-fastify
  • @nestjs/platform-socket.io
  • @nestjs/platform-ws
  • @nestjs/testing
  • @nestjs/websockets
  • Other (see below)

Other package

No response

NestJS version

10.3.2

Packages versions

[Nest Platform Information]
platform-express version : 10.3.8
schematics version       : 10.1.1
testing version          : 10.3.8
common version           : 10.3.8
core version             : 10.3.8
cli version              : 10.3.2

Node.js version

v20.11.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

@shreyas-segu shreyas-segu added the needs triage This issue has not been looked into label May 3, 2024
@RobinKemna
Copy link

Hi @shreyas-segu this is already discussed here: nestjs/docs.nestjs.com#2424

I would suggest du use a custom validation pipe until it is implemented in the framework directly.

This is a adjusted copy of what was already mentioned in the original thread - but it should work with your example as I am using the exact same structure / definition of payload.

import { ParseFilePipe, PipeTransform } from '@nestjs/common';

export class ParseFilesPipe implements PipeTransform<Express.Multer.File[]> {
    constructor(private readonly pipe: ParseFilePipe) {}

    async transform(
        files: Express.Multer.File[] | { [key: string]: Express.Multer.File[] },
    ) {
        for (const file of Object.values(files).flat())
            await this.pipe.transform(file);

        return files;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage This issue has not been looked into
Projects
None yet
Development

No branches or pull requests

2 participants