feat: Moving S3 from AWS to minio
This commit is contained in:
41
v1/src/lib/3R/S3/index.js
Normal file
41
v1/src/lib/3R/S3/index.js
Normal file
@@ -0,0 +1,41 @@
|
||||
"use strict";
|
||||
const Minio = require( 'minio' );
|
||||
const apiConfig = require( '../../../config/apiConfig.json' );
|
||||
|
||||
const minioConfig = apiConfig.S3.driver.minio;
|
||||
|
||||
const minioClient = new Minio.Client({
|
||||
endPoint: minioConfig.endPoint,
|
||||
port: minioConfig.port,
|
||||
useSSL: minioConfig.useSSL,
|
||||
accessKey: minioConfig.accessKey,
|
||||
secretKey: minioConfig.secretKey
|
||||
})
|
||||
|
||||
async function downloadFile( bucket, key, obj_id ){
|
||||
const obj_name = `${key}/${obj_id}`
|
||||
|
||||
const stat = await minioClient.statObject( bucket, obj_name )
|
||||
const dataStream = await minioClient.getObject(bucket, obj_name)
|
||||
const file_data = {
|
||||
ContentType : stat.metaData['content-type']
|
||||
}
|
||||
const chunks = []
|
||||
|
||||
for await (const chunk of dataStream) {
|
||||
chunks.push(chunk)
|
||||
}
|
||||
|
||||
file_data.Body = Buffer.concat(chunks)
|
||||
return file_data
|
||||
}
|
||||
|
||||
async function uploadFile( bucket, key, obj_id, file ){
|
||||
const obj_name = `${key}/${obj_id}`
|
||||
|
||||
const resp = await minioClient.putObject( bucket, obj_name, file.data, file.size, {
|
||||
'content-type' : file.mimetype
|
||||
} )
|
||||
}
|
||||
|
||||
module.exports = { downloadFile, uploadFile };
|
||||
Reference in New Issue
Block a user