'NESTJS download file from another back end API
Trying to bring clarity to this issue. I need to get any attachment file from another back end and return in the nestjs controller.
Service code:
getFile(token: string, orderId: number, fileName: string): Observable<any> {
let url = `${this.configService.get<string>(
'BACKEND_ORDER_BASE_URL',
)}/file/download`;
if (orderId) {
url += `?serviceDistrictId=${orderId}`;
}
if (fileName) {
url += `?fileName=${orderId}`;
}
return this.httpService.get(url, {headers:{Authorization: token
}});
}
Controller code:
@Get('download')
@UseGuards(JwtAuthGuard)
getFile(
@Query('fileName') fileName: string,
@Query('orderId') orderId: number,
@AuthHeader() bearerToken: string,
@Res() res: Response): Observable<any>
{
return this.fileService.getFile(bearerToken, orderId, fileName)
.pipe(
map(response => response.data.pipe(res))
);
}
I get an error when running it: ERROR [ExceptionsHandler] response.data.pipe is not a function TypeError: response.data.pipe is not a function.
Can anybody help with the code solution that gets any file from another back end and returns it in nestjs controller?
Much Thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|