Skip to content

Commit

Permalink
Merge pull request #92 from Samagra-Anamaya/minio-setup
Browse files Browse the repository at this point in the history
chore: saving progress
  • Loading branch information
geeky-abhishek authored Oct 26, 2023
2 parents a1db15f + a54441c commit da66a32
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
3 changes: 2 additions & 1 deletion packages/bff/src/minio/minio.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class MinioService {
bucketName: string,
filename: string,
file: Buffer,
meta?: any,
): Promise<any> {
const _filename = `${uuid.v4()}.${filename.split('.').pop()}`;
const result = await this.minioClient.putObject(
Expand All @@ -31,7 +32,7 @@ export class MinioService {
);

//const url = await this.getFileLink(bucketName, _filename);
return { result: { filename: _filename, msg: result } };
return { filename: _filename, msg: result, meta: meta ?? {} };
}

async getDownloadURL(bucketName: string, filename: string) {
Expand Down
6 changes: 5 additions & 1 deletion packages/bff/src/upload/dto/upload.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@ export class MultiFileUploadDto {
},
})
@IsNotEmpty()
files: any[];
files: Express.Multer.File[];

@ApiProperty()
@IsNotEmpty()
meta: any; // or any other desired type, perhaps an object: meta: Record<string, any>;
}
8 changes: 6 additions & 2 deletions packages/bff/src/upload/upload.controller.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
BadRequestException,
Body,
Controller,
Get,
Param,
Expand Down Expand Up @@ -51,11 +52,14 @@ export class UploadController {
type: MultiFileUploadDto,
})
@UseInterceptors(FilesInterceptor('files'))
async upload(@UploadedFiles() files: Express.Multer.File[]) {
async upload(
@UploadedFiles() files: Express.Multer.File[],
@Body('meta') meta: any,
) {
try {
if (!files || files?.length === 0)
throw new BadRequestException('No Files passed');
const urls = await this.uploadService.uploadFiles(files);
const urls = await this.uploadService.uploadFiles(files, meta);
return urls;
} catch (error) {
throw error;
Expand Down
5 changes: 3 additions & 2 deletions packages/bff/src/upload/upload.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@ export class UploadService {
return result;
}

async uploadFiles(files: any) {
async uploadFiles(files: any, meta: any) {
try {
const urls = await Promise.all(
files.map(async (file) => {
const result = await this.minioService.uploadFile(
this.configService.get<string>('MINIO_BUCKET'),
file.originalname,
file.buffer,
meta,
);
return result;
}),
);
return urls;
return { result: urls };
} catch (error) {
throw error;
}
Expand Down

0 comments on commit da66a32

Please sign in to comment.