monorepo-microservice-rbac/apps/services/aorta/report/src/app.controller.ts

22 lines
657 B
TypeScript
Raw Normal View History

2023-08-27 14:37:59 +08:00
import { Controller } from '@nestjs/common';
import { EventPattern } from '@nestjs/microservices';
import { getFileExt } from './app.util';
import { clientConfig } from './app.config';
import { MinioOSS } from '@tavi/oss';
@Controller()
export class AppController {
2023-10-10 16:48:34 +08:00
@EventPattern('report-upload-image')
2023-08-27 14:37:59 +08:00
async uploadImageHandler({ buffer, originalName }) {
const objectName = Date.now() + '.' + getFileExt(originalName);
const { bucketName, ...config } = clientConfig;
const minio = new MinioOSS(config);
const res = await minio.put({
file: buffer,
objectName,
bucketName,
});
return { res, objectName };
}
}