当前位置: 首页 > 文档资料 > MinIO 帮助文档 >

适用于Amazon S3兼容云存储的Minio JavaScript Library

优质
小牛编辑
118浏览
2023-12-01

MinIO JavaScript Client SDK提供简单的API来访问任何Amazon S3兼容的对象存储服务。

本快速入门指南将向您展示如何安装客户端SDK并执行示例JavaScript程序。有关API和示例的完整列表,请参阅JavaScript客户端API参考文档。

本文假设你已经安装了nodejs

使用NPM下载

npm install --save minio

下载并安装源码

git clone https://github.com/minio/minio-js
cd minio-js
npm install
npm install -g

初使化Minio Client

你需要设置5个属性来链接Minio对象存储服务。

参数描述
endPoint对象存储服务的URL
portTCP/IP端口号。可选值,如果是使用HTTP的话,默认值是80;如果使用HTTPS的话,默认值是443
accessKeyAccess key是唯一标识你的账户的用户ID。
secretKeySecret key是你账户的密码。
useSSLtrue代表使用HTTPS
var Minio = require('minio')

var minioClient = new Minio.Client({
    endPoint: 'play.min.io',
    port: 9000,
    useSSL: true,
    accessKey: 'Q3AM3UQ867SPQQA43P2F',
    secretKey: 'zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG'
});

示例-文件上传

本示例连接到一个对象存储服务,创建一个存储桶并上传一个文件到存储桶中。

我们在本示例中使用运行在 https://play.min.io 上的Minio服务,你可以用这个服务来开发和测试。示例中的访问凭据是公开的。

file-uploader.js

var Minio = require('minio')

// Instantiate the minio client with the endpoint
// and access keys as shown below.
var minioClient = new Minio.Client({
    endPoint: 'play.min.io',
    port: 9000,
    useSSL: true,
    accessKey: 'Q3AM3UQ867SPQQA43P2F',
    secretKey: 'zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG'
});

// File that needs to be uploaded.
var file = '/tmp/photos-europe.tar'

// Make a bucket called europetrip.
minioClient.makeBucket('europetrip', 'us-east-1', function(err) {
    if (err) return console.log(err)

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

    var metaData = {
        'Content-Type': 'application/octet-stream',
        'X-Amz-Meta-Testing': 1234,
        'example': 5678
    }
    // Using fPutObject API upload your file to the bucket europetrip.
    minioClient.fPutObject('europetrip', 'photos-europe.tar', file, metaData, function(err, etag) {
      if (err) return console.log(err)
      console.log('File uploaded successfully.')
    });
});

运行file-uploader

node file-uploader.js
Bucket created successfully in "us-east-1".

mc ls play/europetrip/
[2016-05-25 23:49:50 PDT]  17MiB photos-europe.tar

API文档

完整的API文档在这里。

API文档 : 操作存储桶

API文档 : 操作文件对象

API文档 : 操作对象

API文档 : Presigned操作

API文档 : 存储桶通知

API文档 : 存储桶策略

完整示例

完整示例 : 操作存储桶

完整示例 : 操作文件对象

完整示例 : 操作对象

完整示例 : Presigned操作

完整示例 : 存储桶通知

完整示例 : 存储桶策略

了解更多