项目作者: darshitvvora

项目描述 :
Async Minio(S3 compatible high performance object storage and retrieval) client for promises support in NodeJS
高级语言: HTML
项目地址: git://github.com/darshitvvora/node-minio.git
创建时间: 2019-12-05T11:01:29Z
项目社区:https://github.com/darshitvvora/node-minio

开源协议:MIT License

下载


Node-Minio

Async Minio(S3 compatible high performance object storage and retrieval) client for promises support in NodeJS
An helper library which provides core promisified helper functions for using minio bucket from Node API

Want to contribute to Node-Minio? Please read CONTRIBUTING.md.

Installation

Steps to setup minio on linux server - link

Node-Minio supports stable versions of Node.js 8.11.0 and later. You can install
Node Minio in your project’s node_modules folder.

To install the latest version on npm locally and save it in your package’s
package.json file:

  1. npm install --save node-minio

Usage

  • Initialize Minio Object

    1. const NodeMinio = require('node-minio');
    2. const config = {
    3. minio: {
    4. endPoint: "192.168.23.100",
    5. accessKey: "SN8JBGY43WPMFT0R56fsdfdsf",
    6. secretKey: "fdfdfdfd+3R9e/x4V0F6Xpjtfdsfd",
    7. secure: false,
    8. port: 8000,
    9. },
    10. errorFileUrl: "/sample/errorfile.pdf",
    11. bucket: "sample"
    12. }
    13. const Minio = new NodeMinio(config);
  • Upload a base64 file to Minio Bucket using NodeJS

    1. async function uploadFile(file) {
    2. const { base64: base64String, filename } = file;
    3. const extension = filename.split('.').pop();
    4. const fileName = moment().format('YYYY_MM_DD_hh_mm_ss_a');
    5. const object = `sampleFile/${fileName}.${extension}`;
    6. await Minio.base64Upload({ object, base64String });
    7. return object;
    8. }
  • Generate dynamic URL with expiry to access file from bucket

    1. async function viewFile(fileName) {
    2. const filePath= 'sampleFile/${fileName}.pdf'
    3. const url = await Minio
    4. .viewLink({
    5. object: filePath,
    6. }, false);
    7. return url;
    8. }
  • Lists all the directories in current folder/bucket

    1. async function listFilesList() {
    2. const baseUrl= 'sampleFile/'
    3. const fileList = await Minio
    4. .listDirectoryObjects({ object: baseUrl });
    5. return fileList;
    6. }
  • Download a file from bucket

    1. async function downloadFile(req, res, name) {
    2. const file = {
    3. object: 'sampleFiles/',
    4. name: `${name}_${
    5. moment().format('YYYY-DD-MM')}.${ext}`,
    6. };
    7. return Minio.downloadLinkBase(file)
    8. .then(downloadLink => res.redirect(downloadLink));
    9. }
  • Validate bucket and Download a file from bucket

    1. async function ValidateAndDownloadFile(req,res,name) {
    2. const file = {
    3. object: 'sampleFiles/',
    4. name: `${name}_${
    5. moment().format('YYYY-DD-MM')}.${ext}`,
    6. };
    7. return Minio.downloadLink(file)
    8. .then(downloadLink => res.redirect(downloadLink));
    9. }
  • Used to retry alternative file to be downloaded. Here in tha example below we dont get original file than we search for -rst file and try download it

    1. async function retryFileFromMinio(fileName) {
    2. const retryObject = fileName.path.toLowerCase();
    3. const name = `${fileName}.pdf`.replace(/ /g, '_');
    4. const url = await Minio
    5. .retryDownloadLink({
    6. name,
    7. retryObject,
    8. object: retryObject.replace(/\.pdf$/g, '-rst.pdf'),
    9. });
    10. }
  • Generates and returns presigned URL for HTTP PUT operations.
    Clients may point to this URL to upload objects directly to a bucket even if it is private.
    This presigned URL can have an associated expiration time in seconds after which the URL is no longer valid.
    The default value is 7 days.

    1. async function getUploadLink() {
    2. const url = await Minio
    3. .uploadLink({});
    4. return url;
    5. }
  • Uploads base64 file from temp path(specified path) to bucket

    1. async function uploadFromTemp(file) {
    2. const extension = (file.name || file.filename).split('.').pop().toLowerCase();
    3. minioObject = {
    4. base64String: file.base64,
    5. temp: file.path,
    6. object: `sample/${Id}/${Id
    7. }_${moment().format('DD-MM-YYYY_hh-mm-ss-a')}.${extension}`,
    8. };
    9. const out = await Minio
    10. .uploadTemp(minioObject);
    11. return out;
    12. }
  • Uploads multiple base64 file in one go

    1. return Minio.base64UploadMulti(minioObjects);
  • Copies file from one bucket to another

    1. return Minio.customCopyObject(minioObject);
  • Gets object from minio bucket as a stream

    1. return Minio.getFileStream(minioObject);

Documentation

License

Node-Minio is copyright (c) 2019-present Darshit Vora dvvrocks@gmail.com and
the contributors to Node-Minio.

Node-Minio is free software, licensed under the MIT License. See the
LICENSE file for more details.