UNPKG

@tsed/platform-multer

Version:
50 lines (49 loc) 1.44 kB
import { StoreMerge } from "@tsed/core"; import { PLATFORM_MULTER_OPTIONS } from "../constants/constants.js"; /** * Define multer option for all MultipartFile * * ```typescript * import {PlatformMulterFile, MultipartFile, MulterOptions} from "@tsed/platform-multer"; * import {Controller} from "@tsed/di"; * import {Post} from "@tsed/schema"; * * @Controller('/') * class MyCtrl { * @Post('/file') * private uploadFile(@MultipartFile("file1") file: PlatformMulterFile) { * * } * * @Post('/file') * @MulterOptions({dest: "/other-dir"}) * private uploadFile(@MultipartFile("file1") file: PlatformMulterFile) { * * } * * @Post('/file2') * @MulterOptions({dest: "/other-dir"}) * private uploadFile(@MultipartFile("file1") file: PlatformMulterFile, @MultipartFile("file2") file2: PlatformMulterFile) { * * } * * @Post('/files') * private uploadFile(@MultipartFile("file1") files: PlatformMulterFile[]) { * * } * } * ``` * * See the tutorial on the [multer configuration](/docs/upload-files.md). * * @param {multer.Options} options * @returns {(target: any, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor} * @decorator * @multer */ export function MulterOptions(options) { return (target, propertyKey, descriptor) => { StoreMerge(PLATFORM_MULTER_OPTIONS, { options })(target, propertyKey, descriptor); return descriptor; }; }