ToolJet/server/src/controllers/files.controller.ts
Gandharv 5dbe795d73
feat: add user avatar (#2920)
* feat: add user avatar

* update: @nest/platform-express from 8.0.0 to 8.4.4

* add avatar_id in login response

* add user avatar upload in frontend

* align cross divider with layout icons'

* generate nest model - extensions

* cleanup

* fix tests

* reduce the avatar size on homepage

* fix review comments

* import Express

* add blob to csp
2022-06-02 12:19:49 +05:30

36 lines
965 B
TypeScript

import {
Controller,
Get,
Param,
UseInterceptors,
ClassSerializerInterceptor,
Res,
StreamableFile,
UseGuards,
} from '@nestjs/common';
import { Readable } from 'stream';
import { Response } from 'express';
import { FilesService } from '../services/files.service';
import { JwtAuthGuard } from 'src/modules/auth/jwt-auth.guard';
@Controller('files')
@UseInterceptors(ClassSerializerInterceptor)
export class FilesController {
constructor(private readonly filesService: FilesService) {}
@Get(':id')
@UseGuards(JwtAuthGuard)
async show(@Param('id') id: string, @Res({ passthrough: true }) response: Response) {
const file = await this.filesService.findOne(id);
const stream = Readable.from(file.data);
response.set({
'Content-Disposition': `inline; filename="${file.filename}"`,
'Content-Type': 'image',
});
// https://docs.nestjs.com/techniques/streaming-files
return new StreamableFile(stream);
}
}