full project: admin panel, backend modules, docs
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
import { Controller, Post, UseGuards, Req, UploadedFile, UseInterceptors } from '@nestjs/common';
|
||||
import { Controller, Post, UseGuards, UploadedFile, UseInterceptors, BadRequestException } from '@nestjs/common';
|
||||
import { FileInterceptor } from '@nestjs/platform-express';
|
||||
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
|
||||
import { ApiTags, ApiBearerAuth, ApiBody, ApiConsumes } from '@nestjs/swagger';
|
||||
import { JwtAuthGuard } from '../auth/jwt-auth.guard';
|
||||
import { StorageService } from './storage.service';
|
||||
import { StorageService, StoredFile } from './storage.service';
|
||||
|
||||
@ApiTags('Storage')
|
||||
@Controller('storage')
|
||||
@@ -12,8 +12,12 @@ export class StorageController {
|
||||
@Post('upload')
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiBearerAuth()
|
||||
@ApiConsumes('multipart/form-data')
|
||||
@ApiBody({ schema: { type: 'object', properties: { file: { type: 'string', format: 'binary' } } } })
|
||||
@UseInterceptors(FileInterceptor('file'))
|
||||
upload(@UploadedFile() file: any) {
|
||||
return { url: this.storage.getUploadUrl(file?.originalname) };
|
||||
async upload(@UploadedFile() file: StoredFile) {
|
||||
if (!file) throw new BadRequestException('Archivo requerido');
|
||||
const url = await this.storage.save(file);
|
||||
return { url };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user