nestjs上传视频到minio
时间: 2024-01-03 22:22:14 浏览: 247
以下是使用NestJS上传视频到Minio的示例代码:
```typescript
import { Controller, Post, UseInterceptors, UploadedFile } from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { MinioService } from 'nestjs-minio-client';
@Controller('upload')
export class UploadController {
constructor(private readonly minioService: MinioService) {}
@Post('video')
@UseInterceptors(FileInterceptor('video'))
async uploadVideo(@UploadedFile() video: Express.Multer.File) {
const bucketName = 'videos'; // 设置存储桶名称
const fileName = video.originalname; // 设置文件名为原始文件名
// 上传视频到Minio
await this.minioService.client.putObject(bucketName, fileName, video.buffer);
return 'Video uploaded successfully';
}
}
```
请确保已经安装了`@nestjs/platform-express`和`nestjs-minio-client`依赖,并正确配置了Minio服务的连接信息。
阅读全文