import { Controller, Post, UploadedFile, Get, Param, Res, UseInterceptors, StreamableFile, Header } from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { Response } from 'express';
import { createReadStream } from 'fs';
import { join } from 'path';
@Controller()
export class FileController {
@Get('file/:fileName')
@Header('Content-Type', 'application/json')
downloadFile(@Res({ passthrough: true }) res: Response, @Param('fileName') fileName): StreamableFile {
const file = createReadStream(join(process.cwd(), fileName));
res.set({
'Content-Disposition': 'attachment; filename=' + fileName
});
return new StreamableFile(file);
}
@Get('video/:fileName')
viewVideo(@Res() res: Response, @Param('fileName') fileName: string): string {
const videoPath = join(process.cwd(), fileName)
return fileName;
}
@Post('upload')
@UseInterceptors(FileInterceptor('file'))
uploadFile(@UploadedFile() file: Express.Multer.File) {
console.log(file.filename);
console.log(file.path);
return file.filename;
}
}
Here is my nest js code
below are required logs
[Nest] 28008 - 04/18/2024, 1:51:21 PM LOG [RoutesResolver] FileController {/file}: +0ms [Nest] 28008 - 04/18/2024, 1:51:21 PM LOG [RouterExplorer] Mapped {/file/:fileName, GET} route +1ms [Nest] 28008 - 04/18/2024, 1:51:21 PM LOG [RouterExplorer] Mapped {/file/upload, POST} route +0ms
my route for video/:fileName is not getting mapped.
How to solve ? i have restarted application several times.
I restarted application several times, tried different routes as well, tried chat gpt but could not solve.