본문 바로가기
Dev/etc

download all files from an object in MinIO

by 펭귄안에 온천 2023. 3. 29.
728x90
반응형

MiniO 콘솔에서는 모든 오브젝트(파일)을 한번에 다운로드 받을 수 없다

 

결국 파일 하나씩 다운로드 받는걸 프로그래밍해서 전체 다운로드 받아야 함

 

https://www.npmjs.com/package/minio

 

minio

S3 Compatible Cloud Storage client. Latest version: 7.0.33, last published: 5 days ago. Start using minio in your project by running `npm i minio`. There are 400 other projects in the npm registry using minio.

www.npmjs.com

 

Minio Npm을 사용해서 가능함

 

const Minio = require('minio')

class DownloadObj
{
    constructor()
    {
        this.endPoint = 'ip',
        this.port = 9000,
        this.accessKey = 'accessKey',
        this.secretKey = 'secretKey'
        this.bucketsNm = "Bucket Name";
        this.path = null; //폴더경로 , prefix
        this.minioClient = null;
        this.run();
    }

    async run()
    {
        this.init();
        this.objDown();
    }

    init()
    {
        let self = this;
        this.minioClient = new Minio.Client({
            endPoint:self.endPoint,
            port: self.port,
            useSSL: false,
            accessKey: self.accessKey,
            secretKey: self.secretKey
        });
    }

    objDown()
    {
        let self = this;
        let stream = this.minioClient.extensions.listObjectsV2WithMetadata(this.bucketsNm,this.path, true,'')

        stream.on('data', function(obj) { 
             self.download( obj.name )
        });
        stream.on('error', function(err) { 
            console.log( err )
        });
    }

    download(sFileNm){
        this.minioClient.fGetObject(this.bucketsNm, sFileNm, `./${this.bucketsNm}/${sFileNm}`, function(err) {
            if (err) {
                console.log(`[ ### Download fail ] ${sFileNm}`)
            }else{
                console.log(`[ Download success ] ${sFileNm}`)
            }
        });
    }
}
new DownloadObj();

Sample Git 

https://github.com/Chung10Kr/DownloadMinio

 

GitHub - Chung10Kr/DownloadMinio

Contribute to Chung10Kr/DownloadMinio development by creating an account on GitHub.

github.com

 

반응형