#file + JSON uploading validation

1 messages · Page 1 of 1 (latest)

tiny osprey
#

Hello , i'me trying to upload a product with an image , I've read that I've to send it in Form-data with 2 fields one with an image file and the second with a json file (maybe its not the way idk so tell me if you know a better way...)

I've successfully intercept them , but i cant validate them separately
I've tried many ways , but nothing work

someone have an idea how to achieve this?

here is my basic controller :

  @Post()
  @UseInterceptors(FileFieldsInterceptor([
    {name:'image',maxCount:1},
    {name:'product_description',maxCount:1}
  ]))
  createAndConnect(
    @UploadedFile()file: Express.Multer.File) {
    return {file}
  }

even you have a completely different way to do that tell me , i want to learn

old geyser
#

How complex is the body?

tiny osprey
#

nested objects and arrays

old geyser
#

Oh boy. Okay, yeah can't do anything simple then

tiny osprey
tiny osprey
#

file + JSON uploading validation

buoyant wyvern
#

You can create a custom pipe where you manually validate them separately.

look into this in the docs https://docs.nestjs.com/techniques/file-upload#file-validation

tiny osprey