Spaces:
Runtime error
Runtime error
File size: 955 Bytes
96ed566 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
import 'multer';
import { FilesInterceptor } from '@nestjs/platform-express';
import { UseInterceptors, UploadedFiles, Post, Controller, Bind } from '@nestjs/common';
import { MulterFiles } from '@/infra/http/utils/multer.file';
import { ExternalService } from '@/infra/http/services/external.service';
import { ImagePresenter } from '@/infra/http/presenters/image.presenter';
import { Image } from '@/domain/alcremie/enterprise/entities/image';
@Controller('upload')
export class UploadController {
constructor(private readonly externalService: ExternalService) {}
@Post()
@UseInterceptors(FilesInterceptor('image'))
@Bind(UploadedFiles())
async uploadFile(files: MulterFiles) {
let images: Image[] = [];
for (let file of files) {
const data = await this.externalService.uploadImage(file);
if (data) {
images.push(data);
}
}
return {
images: images.map(ImagePresenter.toHTTP),
};
}
}
|