代码拉取完成,页面将自动刷新
import { Controller, Get, Post, UploadedFile, UseInterceptors, Query, HttpCode, Body, Req } from '@nestjs/common'
import { FileInterceptor } from '@nestjs/platform-express'
import { ApiTags, ApiOperation, ApiConsumes, ApiBody, ApiBearerAuth } from '@nestjs/swagger'
import { ResultData } from '../../common/utils/result'
import { OssService } from './oss.service'
import { FindOssDto } from './dto/find-oss.dto'
import { ApiResult } from '../../common/decorators/api-result.decorator'
import { OssEntity } from './oss.entity'
@ApiTags('文件存储')
@ApiBearerAuth()
@Controller('oss')
export class OssController {
constructor(private readonly ossService: OssService) {}
@Post('upload')
@ApiOperation({ summary: '文件上传,返回 url 地址' })
@ApiConsumes('multipart/form-data')
@ApiBody({
schema: {
type: 'object',
properties: {
file: {
description: '文件',
type: 'string',
format: 'binary',
},
business: {
description: '上传文件描述,可以是纯字符串,也可以是JSON字符串',
type: 'string',
format: 'text',
},
},
},
})
@HttpCode(200)
@UseInterceptors(FileInterceptor('file'))
@ApiResult(OssEntity)
async uploadFile(
@UploadedFile() file: Express.Multer.File,
@Body() params: { business: string },
@Req() req,
): Promise<ResultData> {
return await this.ossService.create([file], params.business || '', req.user)
}
@Get('list')
@ApiOperation({ summary: '查询文件上传列表' })
@ApiResult(OssEntity, true, true)
async findList(@Query() search: FindOssDto): Promise<ResultData> {
return await this.ossService.findList(search)
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。