#File Upload inside request body DTO

1 messages · Page 1 of 1 (latest)

brittle crown
#

I'm currently have a quite robust controller that now needed to add request body by uploading a file inside its DTO

//then
{
  Description: 'string',
  Students: [
    {
      Name: 'string',
      Age: number
    }
  ]
}
//now
{
  Description: 'string',
  Students: [
    {
      Name: 'string',
      Age: number
      Image: Bytes
    }
  ]
}

I need to input the image inside the DTO and I think changing those DTO intomultipart/form-data is a no-go since it will change major flow of the code. Is there a possible way to achieve this? Tried to solve the problem but stuck

deep basin
#

If you're uploading an image, you really should be using multipart/form-data

brittle crown
# deep basin If you're uploading an image, you _really_ should be using `multipart/form-data`

Hi, so I was trying the multipart/form-data but always get the nested property must be either object or array error. For context, I want to have a nested array of objects inside the DTO

  @ApiProperty({ type: [Teacher] })
  @ValidateNested()
  @Type(() => Teacher)
  // @ArrayMinSize(1)
  Teacher: Teacher[];

  @ApiProperty({ type: [Student] })
  @ValidateNested()
  @Type(() => Student)
  // @ArrayMinSize(1)
  Student: Student[];

  @ApiProperty({ type: [Class] })
  @ValidateNested()
  @Type(() => Class)
  // @ArrayMinSize(1)
  Class: Class[];

using {each: true} options didn't help. Am I missing something?

deep basin
#

Where are you getting that error?

brittle crown
deep basin
#

Can you show the stack trace? I'm quite sure I follow

brittle crown
#

Okay sure, I'll just provide the screenshot instead. Here you go