I am new to nestJs.
i get this error
[Nest] 60297 - 08/26/2023, 5:21:03 PM ERROR [ExpressAdapter] Premature close Error: Premature close at new NodeError (node:internal/errors:405:5) at ServerResponse.onclose (node:internal/streams/end-of-stream:154:30) at ServerResponse.emit (node:events:526:35) at emitCloseNT (node:_http_server:996:10) at Socket.onServerResponseClose (node:_http_server:278:5) at Socket.emit (node:events:526:35) at TCP.<anonymous> (node:net:323:12)
this is my code
`
@Get('avatar')
@HttpCode(HttpStatus.OK)
@ApiQuery({ name: 'id', required: false })
@ApiConsumes('multipart/form-data')
@Header('Content-Disposition', 'inline')
async getAvatar(
@GetUserId() userId: string,
@Res({ passthrough: true }) response: Response,
@Query('id') id?: string,
) {
const user = await this.userRepository.getUserById(id ?? userId);
if (!user) {
throw new NotFoundException(`User not found`);
}
const { avatarType } = await this.userRepository.getProfile(id ?? userId);
response.set('Content-Type', avatarType);
return new StreamableFile(
createReadStream(join(process.cwd(), `./upload/${user.id}`))
);
}
`
Minimum reproduction code
i provided snipts code.
Steps to reproduce
No response
Expected behavior
i change it to express version and it works fine
`
@Get('avatar')
@HttpCode(HttpStatus.OK)
@ApiQuery({ name: 'id', required: false })
@ApiConsumes('multipart/form-data')
async getAvatar(
@GetUserId() userId: string,
@Res() response: Response,
@Query('id') id?: string,
) {
const user = await this.userRepository.getUserById(id ?? userId);
if (!user) {
throw new NotFoundException(User not found);
}
const { avatarType } = await this.userRepository.getProfile(id ?? userId);
response
.contentType(avatarType)
.download(join(process.cwd(), ./upload/${user.id}));
Is there an existing issue for this?
Current behavior
I am new to nestJs. i get this error
[Nest] 60297 - 08/26/2023, 5:21:03 PM ERROR [ExpressAdapter] Premature close Error: Premature close at new NodeError (node:internal/errors:405:5) at ServerResponse.onclose (node:internal/streams/end-of-stream:154:30) at ServerResponse.emit (node:events:526:35) at emitCloseNT (node:_http_server:996:10) at Socket.onServerResponseClose (node:_http_server:278:5) at Socket.emit (node:events:526:35) at TCP.<anonymous> (node:net:323:12)
this is my code ` @Get('avatar') @HttpCode(HttpStatus.OK) @ApiQuery({ name: 'id', required: false }) @ApiConsumes('multipart/form-data') @Header('Content-Disposition', 'inline') async getAvatar( @GetUserId() userId: string, @Res({ passthrough: true }) response: Response, @Query('id') id?: string, ) { const user = await this.userRepository.getUserById(id ?? userId);} `
Minimum reproduction code
i provided snipts code.
Steps to reproduce
No response
Expected behavior
i change it to express version and it works fine ` @Get('avatar') @HttpCode(HttpStatus.OK) @ApiQuery({ name: 'id', required: false }) @ApiConsumes('multipart/form-data') async getAvatar( @GetUserId() userId: string, @Res() response: Response, @Query('id') id?: string, ) { const user = await this.userRepository.getUserById(id ?? userId);
} `
Package
Other package
No response
NestJS version
10.1.16
Packages versions
Node.js version
18.17.0
In which operating systems have you tested?
Other
i asked in Discord, and I got a response from the moderator this could be an error.