How to use the @nestjs/swagger.ApiImplicitFile function in @nestjs/swagger

To help you get started, we’ve selected a few @nestjs/swagger examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NarHakobyan / awesome-nest-boilerplate / src / modules / auth / auth.controller.ts View on Github external
type: LoginPayloadDto,
        description: 'User info with access token',
    })
    async userLogin(
        @Body() userLoginDto: UserLoginDto,
    ): Promise {
        const userEntity = await this.authService.validateUser(userLoginDto);

        const token = await this.authService.createToken(userEntity);
        return new LoginPayloadDto(userEntity.toDto(), token);
    }

    @Post('register')
    @HttpCode(HttpStatus.OK)
    @ApiOkResponse({ type: UserDto, description: 'Successfully Registered' })
    @ApiImplicitFile({ name: 'avatar', required: true })
    @UseInterceptors(FileInterceptor('avatar'))
    async userRegister(
        @Body() userRegisterDto: UserRegisterDto,
        @UploadedFile() file: IFile,
    ): Promise {
        const createdUser = await this.userService.createUser(
            userRegisterDto,
            file,
        );

        return createdUser.toDto();
    }

    @Get('me')
    @HttpCode(HttpStatus.OK)
    @UseGuards(AuthGuard)
github neoteric-eu / nestjs-auth / src / app / media / media.controller.ts View on Github external
import {MediaUploadDto} from './dto/media-upload.dto';

@ApiUseTags('media')
@ApiBearerAuth()
@UseGuards(AuthGuard('jwt'))
@Controller('media')
export class MediaController {

	private logger = new AppLogger(MediaController.name);

	constructor(@Inject(AWS_CON_TOKEN) private readonly awsConnection) {}

	@Post('upload')
	@UseInterceptors(FileInterceptor('media'))
	@ApiConsumes('multipart/form-data')
	@ApiImplicitFile({ name: 'media', required: true, description: 'Any media file' })
	@ApiResponse({ status: 200, description: 'OK', type: MediaUploadDto })
	public uploadFile(@UploadedFile() file) {
		return file;
	}

	@MessagePattern({ cmd: MEDIA_CMD_DELETE })
	public async onMediaDelete(homeMedia: HomeMediaEntity): Promise {
		const key = new URL(homeMedia.url).pathname.substring(1);
		this.logger.debug(`[onMediaDelete] Going to remove key ${key} from bucket ${config.aws.s3.bucket_name}`);
		const s3 = new S3();
		s3.deleteObject({
			Bucket: config.aws.s3.bucket_name,
			Key: key
		}).promise().then(() => {
			this.logger.debug(`[onMediaDelete] item with key: ${key} removed from bucket`);
		}).catch(() => {
github ZhiXiao-Lin / nestify / server / src / api / controllers / storage.controller.ts View on Github external
import { resolve } from 'path';
import { UploadActionType, StorageType } from '../../common/aspects/enum';
import { ImportService } from '../../common/services/import.service';
import { Logger } from '../../common/lib/logger';
import { Qiniu } from '../../common/lib/qiniu';

@Api('storage')
@ApiUseTags('storage')
@ApiBearerAuth()
@UseGuards(AuthGuard())
export class StorageController {
	constructor(private readonly importService: ImportService) { }

	@Post()
	@ApiConsumes('multipart/form-data')
	@ApiImplicitFile({ name: 'file', required: true })
	async upload(@Req() req, @Res() res) {
		const files = req.raw.files;

		if (Object.keys(files).length == 0) {
			throw new BadRequestException('没有上传任何文件');
		}

		const file = files.file;
		const action = req.raw.body.action || UploadActionType.UPLOAD;

		switch (action) {
			case UploadActionType.IMPORT:
				const target = req.raw.body.target;
				if (!target) throw new BadRequestException('参数 target 缺失');

				Logger.log(target, 'StorageController::import');