src/storage/storage.controller.ts
storage
Storage Controller
Methods |
download | ||||||
download(key: string)
|
||||||
Decorators :
@Get(':key')
|
||||||
Defined in src/storage/storage.controller.ts:51
|
||||||
Parameters :
Returns :
any
|
upload | |||||||||
upload(user: TokenPayload, file: Express.Multer.File)
|
|||||||||
Decorators :
@UseInterceptors(undefined)
|
|||||||||
Defined in src/storage/storage.controller.ts:43
|
|||||||||
Upload files that belong to a tenant like images
Parameters :
Returns :
any
|
import {
Controller,
Get,
Param,
Post,
StreamableFile,
UploadedFile,
UseInterceptors,
} from "@nestjs/common";
import { FileInterceptor } from "@nestjs/platform-express";
import { ApiBody, ApiConsumes } from "@nestjs/swagger";
import { Role } from "../auth/roles/role.enum";
import { Secured } from "../auth/secure.decorator";
import { Token, TokenPayload } from "../auth/token.decorator";
import { FileUploadDto } from "./dto/file-upload.dto";
import { FilesService } from "./files.service";
/**
* Storage Controller
*/
@Controller("storage")
export class StorageController {
/**
* Constructor
* @param filesService The files service
*/
constructor(private filesService: FilesService) {}
/**
* Upload files that belong to a tenant like images
* @param user
* @param file
* @returns
*/
@UseInterceptors(FileInterceptor("file"))
@Secured([Role.Issuances])
@ApiConsumes("multipart/form-data")
@ApiBody({
description: "List of cats",
type: FileUploadDto,
})
@Post()
upload(
@Token() user: TokenPayload,
@UploadedFile() file: Express.Multer.File,
) {
return this.filesService.saveUserUpload(user.entity!.id, file, true);
}
@Get(":key")
download(@Param("key") key: string) {
return this.filesService.getStream(key).then(
(stream) =>
new StreamableFile(stream.stream, {
disposition: "attachment",
type: stream.contentType,
length: stream.size,
}),
);
}
}