Closed SGAMERyu closed 11 months ago
This worked fine when I ran it on my machine. I updated the controller to send back the properties as well, just to show how it's being read:
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
@Post('add')
@UseInterceptors(
FileFieldsInterceptor([
{ name: 'poster', maxCount: 1 },
{ name: 'icon', maxCount: 1 },
]),
)
async add(@UploadedFiles() files, @Body() body) {
console.log(files);
console.log(body);
return {
files: Object.keys(files).map((file: any) => ({
fieldName: files[file][0].fieldname,
originalName: files[file][0].originalname,
})),
body,
};
}
}
Then made this request:
curl http://localhost:3000/add -F 'icon=@README.md' -F 'poster=@README.md' -F 'name=test'
And got this response
HTTP/1.1 201 Created
Connection: keep-alive
Content-Length: 132
Content-Type: application/json; charset=utf-8
Date: Fri, 08 Dec 2023 16:53:14 GMT
Etag: W/"84-w7KuOQTWKSnYt3rEgEUqrCw83s4"
Keep-Alive: timeout=5
X-Powered-By: Express
{
"files": [
{
"fieldName": "icon",
"originalName": "README.md"
},
{
"fieldName": "poster",
"originalName": "README.md"
}
],
"body": {
"name": "test"
}
}
Everything looks fine here
Is there an existing issue for this?
Current behavior
To upload multiple files (all with different field name keys) but nest only return one file other key file is return emptry string
Minimum reproduction code
https://codesandbox.io/p/devbox/upbeat-sea-rtxtwx?file=%2Fsrc%2Fapp.controller.ts%3A12%2C29
Steps to reproduce
No response
Expected behavior
return all files
Package
Other package
No response
NestJS version
10.0.0
Packages versions
Node.js version
v21.2.0
In which operating systems have you tested?
Other
No response