I have the following api endpoint in my backend:
@ApiPost('download/:id', { type: OutputStatusDto, description: 'Download file from URL' })
async downloadFile(@Param() params: InputIdDto, @Res() res: Response) {
const file = await this._fileService.findOne({ where: { id: params.id } });
const { buffer } = await this._fileService.downloadFile(file.url);
res.set({
'Content-Type': 'application/octet-stream',
'Content-Disposition': `attachment; filename=${file.originalname}`,
'Content-Length': buffer.length,
});
res.end(buffer);
}
Now in my frontent I do the following:
export const downloadFile = (id: string) =>
axios
.get<any>(`${process.env.NEXT_PUBLIC_API_URL}/stripe/file/download/${id}`, {
responseType: 'blob',
})
.then((res: AxiosResponse<any>) => {
console.log(res);
return {
data: res.data,
filename: '...',
};
});
Unfortunately, the Content-Disposition
header is not visible:
I wanted to use it to extract filename
. Why it does not work?