Skip to content

Latest commit

 

History

History
200 lines (146 loc) · 9.16 KB

README_zh_CN.md

File metadata and controls

200 lines (146 loc) · 9.16 KB

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

NPM

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

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

本文假设你已经安装了nodejs

使用NPM下载

minio>7.1.0 拥有自带的类型定义,不再需要安装 @types/minio

下载并安装源码

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

初使化Minio Client

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

参数 描述
endPoint 对象存储服务的URL
port TCP/IP端口号。可选值,如果是使用HTTP的话,默认值是80;如果使用HTTPS的话,默认值是443
accessKey Access key是唯一标识你的账户的用户ID。
secretKey Secret key是你账户的密码。
useSSL true代表使用HTTPS
import * as Minio from 'minio'

const 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

import * as Minio from 'minio'

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

// File that needs to be uploaded.
const 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".')

    const 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操作

完整示例 : 存储桶通知

完整示例 : 存储桶策略

了解更多

贡献

贡献者指南

Build Status Build status