@zola_do/minio
v0.1.10
Published
MinIO object storage for NestJS
Readme
@zola_do/minio
MinIO object storage integration for NestJS applications.
Installation
# Install individually
npm install @zola_do/minio
# Or via meta package
npm install @zola_do/nestjs-sharedNote: If installation fails due to nestjs-minio-client postinstall script, use npm install --ignore-scripts.
Usage
Module Setup
import { Module } from '@nestjs/common';
import { MinIoModule } from '@zola_do/minio';
@Module({
imports: [MinIoModule],
})
export class AppModule {}Uploading Files
import { Injectable } from '@nestjs/common';
import { MinIOService, BucketNameEnum } from '@zola_do/minio';
@Injectable()
export class FileUploadService {
constructor(private readonly minioService: MinIOService) {}
async uploadFile(file: Express.Multer.File, bucketName: string) {
return await this.minioService.upload(file, bucketName);
// Returns { filepath, bucketName, contentType, originalname }
}
async uploadBuffer(
buffer: Buffer,
originalname: string,
mimetype: string,
bucketName: string,
) {
return await this.minioService.uploadBuffer(
buffer,
originalname,
mimetype,
bucketName,
);
}
}Presigned URLs
Generate presigned upload URLs for client-side uploads:
const { presignedUrl, file } = await this.minioService.generatePresignedUploadUrl(
{ originalname: 'document.pdf', contentType: 'application/pdf' },
'documents/',
);
// Send presignedUrl to client; they upload directly to MinIODownloading Files
const stream = await this.minioService.downloadBuffer({
filepath: 'path/to/file.pdf',
bucketName: BucketNameEnum.MEGP,
});Environment Variables
| Variable | Description |
|----------|-------------|
| MINIO_ENDPOINT | MinIO server endpoint |
| MINIO_PORT | MinIO port (default: 443) |
| MINIO_USESSL | Use SSL (default: true) |
| MINIO_ACCESSKEY | MinIO access key |
| MINIO_SECRETKEY | MinIO secret key |
| DURATION_OF_PRE_SIGNED_DOCUMENT | Presigned URL expiry in seconds (default: 120) |
Exports
MinIoModule— Register the MinIO moduleMinIOService— Upload, download, presigned URLsBucketNameEnum— Bucket name constantsPresignedFileUploadDto— DTO for presigned upload responses
Related Packages
- @zola_do/document-manipulator — Uses MinIO for document storage
