Can't get the multiple uploaded files
swdreams opened this issue · 2 comments
swdreams commented
I posted multiple files by form data. e.g. files[] = Array.
And I wanted to get them in my controller like the following:
@Post('upload')
@Auth([])
@HttpCode(HttpStatus.CREATED)
@ApiFile({ name: 'files[]', isArray: true })
async upload(@Body() createPostDto: Record<string, string>, @AuthUser() user: UserEntity, @UploadedFiles() files: IFile[]) {
console.log('total files:', files.length);
for (const [index, file] of files.entries()) {
console.log(index, file.fieldname, file.originalname, file.size, file.mimetype);
}
// ...
}
But unfortunately, it doesn't seem to work correctly. When I upload a file, I can get it properly.
Frontend: formdata: file: File
Backend: @apiFile({ name: 'file' })...
But for files array, it doesn't work. Could you advise on it?
Here are nestjs versions:
"@nestjs/axios": "^0.0.7",
"@nestjs/common": "^8.2.6",
"@nestjs/config": "^1.1.6",
"@nestjs/core": "^8.2.6",
"@nestjs/cqrs": "^8.0.1",
"@nestjs/jwt": "^8.0.0",
"@nestjs/microservices": "^8.2.6",
"@nestjs/passport": "^8.1.0",
"@nestjs/platform-express": "^8.2.6",
"@nestjs/serve-static": "^2.2.2",
"@nestjs/swagger": "^5.1.5",
"@nestjs/terminus": "^8.0.4",
"@nestjs/typeorm": "^8.0.3",
NarHakobyan commented
Hey, could you please send example of the request which you are sending?
On Mon, 25 Jul 2022 at 04:03 Senior Software Engineer & Architect < ***@***.***> wrote:
I posted multiple files by form data. e.g. files[] = Array.
And I wanted to get them in my controller like the following:
@post('upload')
@Auth([])
@httpcode(HttpStatus.CREATED)
@apiFile({ name: 'files[]', isArray: true })
async ***@***.***() createPostDto: Record<string, string>, @authuser() user: UserEntity, @uploadedfiles() files: IFile[]) {
console.log('total files:', files.length);
for (const [index, file] of files.entries()) {
console.log(index, file.fieldname, file.originalname, file.size, file.mimetype);
}
// ...
}
But unfortunately, it doesn't seem to work correctly. When I upload a
file, I can get it properly.
Frontend: formdata: file: File
Backend: @apiFile <https://github.com/apiFile>({ name: 'file' })...
But for files array, it doesn't work. Could you advise on it?
Here are nestjs versions:
***@***.***/axios": "^0.0.7",
***@***.***/common": "^8.2.6",
***@***.***/config": "^1.1.6",
***@***.***/core": "^8.2.6",
***@***.***/cqrs": "^8.0.1",
***@***.***/jwt": "^8.0.0",
***@***.***/microservices": "^8.2.6",
***@***.***/passport": "^8.1.0",
***@***.***/platform-express": "^8.2.6",
***@***.***/serve-static": "^2.2.2",
***@***.***/swagger": "^5.1.5",
***@***.***/terminus": "^8.0.4",
***@***.***/typeorm": "^8.0.3",
—
Reply to this email directly, view it on GitHub
<#281>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AANS6ASJFDHXUEGB2FR3O6DVVXRVFANCNFSM54QRCKLA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
--
Best Regards,
Narek
swdreams commented
Hi @NarHakobyan
Sorry for my mistake, I could get it working.
It works perfectly as I expect!
Thanks for your time.
Liki