Skip to content

Commit

Permalink
feat(#416): Adding minio connection utils
Browse files Browse the repository at this point in the history
  • Loading branch information
tholulomo committed Jul 18, 2023
1 parent a7b663e commit 7a3a512
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions resfulservice/src/utils/minio.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const Minio = require('minio');
const { MinioBucket } = require('../../config/constant');
const env = process.env;

const minioClient = new Minio.Client({
endPoint: 'minio',
port: parseInt(env.MINIO_PORT),
useSSL: false,
accessKey: env.MINIO_ROOT_USER,
secretKey: env.MINIO_ROOT_PASSWORD
});

minioClient.bucketExists(env.MINIO_BUCKET ?? MinioBucket, function (err, exists) {
if (err) {
return console.log(err);
}
if (exists) {
return console.log('Bucket exists.');
} else {
minioClient.makeBucket(env.MINIO_BUCKET ?? MinioBucket, 'us-east-1', function (err) {
if (err) return console.log(err);

console.log('Bucket created successfully in "us-east-1".');
});
}
});

module.exports = minioClient;

0 comments on commit 7a3a512

Please sign in to comment.