@zola_do/minio 0.1.9 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +103 -0
- package/package.json +5 -2
package/README.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# @zola_do/minio
|
|
2
|
+
|
|
3
|
+
MinIO object storage integration for NestJS applications.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
# Install individually
|
|
9
|
+
npm install @zola_do/minio
|
|
10
|
+
|
|
11
|
+
# Or via meta package
|
|
12
|
+
npm install @zola_do/nestjs-shared
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
**Note:** If installation fails due to `nestjs-minio-client` postinstall script, use `npm install --ignore-scripts`.
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
|
|
19
|
+
### Module Setup
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { Module } from '@nestjs/common';
|
|
23
|
+
import { MinIoModule } from '@zola_do/minio';
|
|
24
|
+
|
|
25
|
+
@Module({
|
|
26
|
+
imports: [MinIoModule],
|
|
27
|
+
})
|
|
28
|
+
export class AppModule {}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Uploading Files
|
|
32
|
+
|
|
33
|
+
```typescript
|
|
34
|
+
import { Injectable } from '@nestjs/common';
|
|
35
|
+
import { MinIOService, BucketNameEnum } from '@zola_do/minio';
|
|
36
|
+
|
|
37
|
+
@Injectable()
|
|
38
|
+
export class FileUploadService {
|
|
39
|
+
constructor(private readonly minioService: MinIOService) {}
|
|
40
|
+
|
|
41
|
+
async uploadFile(file: Express.Multer.File, bucketName: string) {
|
|
42
|
+
return await this.minioService.upload(file, bucketName);
|
|
43
|
+
// Returns { filepath, bucketName, contentType, originalname }
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async uploadBuffer(
|
|
47
|
+
buffer: Buffer,
|
|
48
|
+
originalname: string,
|
|
49
|
+
mimetype: string,
|
|
50
|
+
bucketName: string,
|
|
51
|
+
) {
|
|
52
|
+
return await this.minioService.uploadBuffer(
|
|
53
|
+
buffer,
|
|
54
|
+
originalname,
|
|
55
|
+
mimetype,
|
|
56
|
+
bucketName,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Presigned URLs
|
|
63
|
+
|
|
64
|
+
Generate presigned upload URLs for client-side uploads:
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
const { presignedUrl, file } = await this.minioService.generatePresignedUploadUrl(
|
|
68
|
+
{ originalname: 'document.pdf', contentType: 'application/pdf' },
|
|
69
|
+
'documents/',
|
|
70
|
+
);
|
|
71
|
+
// Send presignedUrl to client; they upload directly to MinIO
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Downloading Files
|
|
75
|
+
|
|
76
|
+
```typescript
|
|
77
|
+
const stream = await this.minioService.downloadBuffer({
|
|
78
|
+
filepath: 'path/to/file.pdf',
|
|
79
|
+
bucketName: BucketNameEnum.MEGP,
|
|
80
|
+
});
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## Environment Variables
|
|
84
|
+
|
|
85
|
+
| Variable | Description |
|
|
86
|
+
|----------|-------------|
|
|
87
|
+
| `MINIO_ENDPOINT` | MinIO server endpoint |
|
|
88
|
+
| `MINIO_PORT` | MinIO port (default: 443) |
|
|
89
|
+
| `MINIO_USESSL` | Use SSL (default: true) |
|
|
90
|
+
| `MINIO_ACCESSKEY` | MinIO access key |
|
|
91
|
+
| `MINIO_SECRETKEY` | MinIO secret key |
|
|
92
|
+
| `DURATION_OF_PRE_SIGNED_DOCUMENT` | Presigned URL expiry in seconds (default: 120) |
|
|
93
|
+
|
|
94
|
+
## Exports
|
|
95
|
+
|
|
96
|
+
- `MinIoModule` — Register the MinIO module
|
|
97
|
+
- `MinIOService` — Upload, download, presigned URLs
|
|
98
|
+
- `BucketNameEnum` — Bucket name constants
|
|
99
|
+
- `PresignedFileUploadDto` — DTO for presigned upload responses
|
|
100
|
+
|
|
101
|
+
## Related Packages
|
|
102
|
+
|
|
103
|
+
- [@zola_do/document-manipulator](../document-manipulator) — Uses MinIO for document storage
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zola_do/minio",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
4
4
|
"description": "MinIO object storage for NestJS",
|
|
5
5
|
"author": "zolaDO",
|
|
6
6
|
"license": "ISC",
|
|
@@ -15,7 +15,10 @@
|
|
|
15
15
|
"default": "./dist/index.js"
|
|
16
16
|
}
|
|
17
17
|
},
|
|
18
|
-
"files": [
|
|
18
|
+
"files": [
|
|
19
|
+
"dist",
|
|
20
|
+
"README.md"
|
|
21
|
+
],
|
|
19
22
|
"scripts": {
|
|
20
23
|
"build": "rimraf dist && tsc",
|
|
21
24
|
"prepublishOnly": "npm run build"
|