Hi NestJS community!
I'm struggling with handling a multipart/form-data request that contains both files and a nested JSON object with arrays. My Flutter client is sending the data correctly, but the JSON arrays aren't being properly parsed on the NestJS side despite using class-transformer.
My setup:
- Frontend: Flutter using dio package
- Backend: NestJS with @nestjs/platform-express, multer, and class-transformer
- Endpoint: POST /api/upload
What I'm trying to do:
Send a request that contains:
- File(s)
- A JSON field that contains an array of objects
Flutter code:
FormData formData = FormData.fromMap({
'file': await MultipartFile.fromFile('path/to/file.pdf'),
'json': jsonEncode({
'user': {
'name': 'John',
'items': [
{ 'id': 1, 'name': 'Item 1' },
{ 'id': 2, 'name': 'Item 2' }
]
}
})
});
await dio.post('http://my-api/upload', data: formData);