Meituan-Dianping/mos-mss

Name: mos-mss

Owner: ????

Description: mtyun MSS(Meituan Storage Service) sdk for Node.js

Created: 2018-01-12 10:33:16.0

Updated: 2018-04-12 07:27:07.0

Pushed: 2018-04-12 07:27:05.0

Homepage: null

Size: 66

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

mss-nodejs-sdk

mtyun MSS(Meituan Storage Service) sdk for Node.js

install
install mos-mss --save

Overview

Constructs a service interface object. Each API operation is exposed as a function on service.

MSS Usage

MSS, Object Storage Service. Equal to well known Amazon S3.

Constructor Details

Constructs a service object. This object has one method for each API operation.

examples:

MSS = require('mos-mss');

client = new MSS({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>'

options:

Method Summary
Bucket Operations
listBucket()

Returns a list of all buckets owned by the authenticated sender of the request.

Examples:

MSS = require('mos-mss');
client = new MSS({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>'


result = client.listBucket();
lt.then(function (res) {
console.log(res);

Parameters:

Return:

createBucket(name[, options])

Creates a new bucket.

Examples:

MSS = require('mos-mss');
client = new MSS({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>'


result = client.createBucket('Bucket Name');
lt.then(function (res) {
console.log(res);

Parameters:

Return:

deleteBucket(name[, options])

Deletes the bucket. All objects (including all object versions and Delete Markers) in the bucket must be deleted before the bucket itself can be deleted.

Examples:

MSS = require('mos-mss');

client = new MSS({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>'


result = client.deleteBucket('Bucket Name');
lt.then(function (res) {
console.log(res);

Parameters:

Return:

getBucketACL(name[, options])

Gets the access control policy for the bucket.

Examples:

MSS = require('mos-mss');
client = new MSS({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>'


result = client.getBucketACL('Bucket Name');
lt.then(function (res) {
console.log(res);

Parameters:

Return:

putBucketACL(name, ACl[, options])

Sets the permissions on a bucket using access control lists (ACL).

Examples:

MSS = require('mos-mss');
client = new MSS({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>'


result = client.putBucketACL('Bucket Name', 'ACL');
lt.then(function (res) {
console.log(res);

Parameters:

Return:

getBucket(name[, options])

This operation is useful to determine if a bucket exists and you have permission to access it.mos

Examples:

MSS = require('mos-mss');
client = new MSS({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>'


result = client.getBucket('Bucket Name');
lt.then(function (res) {
console.log(res);
//res.code === 200 exists

Parameters:

Return:

getBucketLifecycle(name[, options])

Get the bucket object lifecycle.

Examples:

MSS = require('mos-mss');
client = new MSS({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>'


result = client.getBucketLifecycle('Bucket');
lt.then(function (res) {
console.log(res);

Parameters:

Return:

putBucketLifecycle(name[, options])

Set the bucket object lifecycle.

Examples:

MSS = require('mos-mss');
client = new MSS({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>'


result = client.putBucketLifecycle('Bucket', {
lifecycleConfig: {
    Rule: [
        {
            Expiration: {
                Days: 30
            },
            ID: 'STRING_VALUE',
            Filter: {
                Prefix: ''
            }
        }
    ]
}


lt.then(function (res) {
console.log(res);

Parameters:

Return:

deleteBucketLifecycle(name[, options])

Deletes the lifecycle configuration from the bucket.

Examples:

MSS = require('mos-mss');
client = new MSS({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>'


result = client.deleteBucketLifecycle('Bucket');
lt.then(function (res) {
console.log(res);

Parameters:

Return:

getBucketPolicy(name[, options])

Returns the policy of a specified bucket.

Examples:

MSS = require('mos-mss');
client = new MSS({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>'


result = client.getBucketPolicy('test-bucket');
lt.then(function (res) {
console.log(res);

Parameters:

Return:

putBucketPolicy(name[, options])

Replaces a policy on a bucket. If the bucket already has a policy, the one in this request completely replaces it.

Examples:

MSS = require('mos-mss');
client = new MSS({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>'


result = client.putBucketPolicy('test-bucket', {
policy: {
    "Version":"2012-10-17",
    "Statement":[
        // refer ?????
        {
            "Sid":"",
            "Effect":"Allow",
            "Principal": {"AWS": "*"},
            "Action":["s3:PutObject", "s3:PutObjectAcl"],
            "Resource":["arn:aws:s3:::examplebucket/*"]
        },
        // refer ????
        {
            "Sid":"",
            "Effect":"Allow",
            "Principal":{"AWS": "*"},
            "Action":["s3:GetObject"],
            "Resource":["arn:aws:s3:::examplebucket/*"],
            "Condition":{
                "StringLike":{"aws:Referer":["http://www.example.com/*", "http://example.com/*", ""]}
            }
        },
        {
            "Sid":"Allow get requests without referrer",
            "Effect":"Deny",
            "Principal":{"AWS": "*"},
            "Action":["s3:GetObject"],
            "Resource":["arn:aws:s3:::examplebucket/*"],
            "Condition":{
                        "StringNotLike":{"aws:Referer":["http://www.example.com/*", "http://example.com/*", ""]}
            }
        }
    ]
}

lt.then(function (res) {
console.log(res);

Parameters:

Return:

getBucketCors(name[, options])

Returns the cors configuration for the bucket.

Examples:

MSS = require('mos-mss');
client = new MSS({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>'


result = client.getBucketCors('Bucket');
lt.then(function (res) {
console.log(res);

Parameters:

Return:

putBucketCors(name[, options])

Sets the cors configuration for a bucket.

Examples:

MSS = require('mos-mss');
client = new MSS({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>'


result = client.putBucketCors('Bucket', {
CORSConfiguration: {
    CORSRule: [
        {
            AllowedMethod: [
                'GET',
            /* more items */
            ],
            AllowedOrigin: [
                'http://www.example1.com',
                'http://www.example2.com',
            /* more items */
            ],
            AllowedHeader: [
                '*',
            /* more items */
            ],
            MaxAgeSeconds: 0
        },
    /* more items */
    ]
}

lt.then(function (res) {
console.log(res);

Parameters:

Return:

deleteBucketCors(name[, options])

Deletes the cors configuration information set for the bucket.

Examples:

MSS = require('mos-mss');
client = new MSS({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>'


result = client.deleteBucketCors('Bucket');
lt.then(function (res) {
console.log(res);

Parameters:

Return:

Object Operations
putObject(key, file[, options])

Adds an object to a bucket.

Examples:

ile: String
MSS = require('mos-mss');
path = require('path');
client = new MSS({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>',
bucket: 'Bucket'


filePath = path.join(__dirname, './test.json');
result = client.putObject('ObjectKey', filePath);

lt.then(function (res) {
console.log(res);


ile: Buffer
MSS = require('mos-mss');
client = new MSS({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>',
bucket: 'Bucket'


result = client.putObject('ObjectKey', new Buffer('test'));
lt.then(function (res) {
console.log(res);

Parameters:

Return:

putStream(key, file[, options])

Adds an object to a bucket.

Examples:

MSS = require('mos-mss');
path = require('path');
fs = require('fs');
client = new MSS({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>',
bucket: 'Bucket'



filePath = path.join(__dirname, './test.json');
stream = fs.createReadStream(filePath);

result = client.putStream('ObjectKey', stream);
lt.then(function (res) {
console.log(res);

Parameters:

Return:

multipartUpload(key, file[, options])

Upload file with MSS multipart.

Examples:

iecewise upload
MSS = require('mos-mss');
path = require('path');
fs = require('fs');
client = new MSS({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>',
bucket: 'Bucket'


write = function (data) {
return fs.writeFileSync(path.join(__dirname, './data/checkpoint.txt'), data);


result = client.multipartUpload('ObjectKey', path.join(__dirname, './img/test-big.json'), {
progress: function (p, checkpoint) {
    write(JSON.stringify(checkpoint));
    console.log('Progress: ' + p);
}


lt.then(function (res) {
console.log(res);


reakpoint upload
MSS = require('mos-mss');
path = require('path');
fs = require('fs');
client = new MSS({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>',
bucket: 'Bucket'


read = function () {
return fs.readFileSync(path.join(__dirname, './data/checkpoint.txt'), 'utf-8');

checkpoint = JSON.parse(read());

object = client.multipartUpload('Bucket', path.join(__dirname, './data/test-big.json'), {
checkpoint: checkpoint,
progress: function (p, checkpoint) {
    console.log('Progress: ' + p, checkpoint);
}


ct.then(function (data) {
console.log(data);

Parameters:

Return:

closeMultipartUpload(key, uploadId)

Abort a multipart upload for object.

Examples:

MSS = require('mos-mss');
client = new MSS({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>',
bucket: 'Bucket'


result = client.closeMultipartUpload('Bucket', 'UploadId');

lt.then(function (res) {
console.log(res);

Parameters:

Return:

getParts(key, uploadId)

a list of parts that has been uploaded.

Examples:

MSS = require('mos-mss');
client = new MSS({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>',
bucket: 'Bucket'


result = client.getParts('Bucket', 'UploadId');

lt.then(function (res) {
console.log(res);

Parameters:

Return:

getObject(key, path[, options])

Retrieves objects from mos S3.

Examples:

MSS = require('mos-mss');
path = require('path');
client = new MSS({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>',
bucket: 'Bucket'


result = client.getObject('test.json', path.join(__dirname, './data/test.json'));

lt.then(function (data) {
console.log(data);

Parameters:

Return:

getBuffer(key[, options])

Examples:

MSS = require('mos-mss');
client = new MSS({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>',
bucket: 'Bucket'


result = client.getBuffer('test');

lt.then(function (res) {
console.log(res);

Parameters:

Return:

getStream(key[, options])

Examples:

MSS = require('mos-mss');
client = new MSS({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>',
bucket: 'Bucket'


writeStream = fs.createWriteStream(path.join(__dirname, './data/test.json'));

result = client.getStream('ObjectKey');

lt.then(function (data) {
data.stream.pipe(writeStream);
data.stream.on('end', function () {
    console.log('success');
});
data.stream.on('error', function (err) {
    console.log('fail', err);
});

Parameters:

Return:

listObject([options])

Returns all of the objects in a bucket.

Examples:

MSS = require('mos-mss');
client = new MSS({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>',
bucket: 'Bucket'



result = client.listObject();
lt.then(function (res) {
console.log(res);

Parameters:

Return:

copyObject(from, to[, options])

Creates a copy of an object that is already stored in mss S3.

Examples:

MSS = require('mos-mss');
client = new MSS({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>',
bucket: 'Bucket'


result = client.copyObject(?from?, 'to');

lt.then(function (res) {
console.log(res);

Parameters:

Return:

getMeta(key[, options])

Retrieves objects meta from mos S3.

Examples:

MSS = require('mos-mss');
client = new MSS({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>',
bucket: 'Bucket'


result = client.getMeta('ObjectKey');
lt.then(function (res) {
console.log(res);

Parameters:

Return:

deleteObject(key[, options])

Deletes an object.

Examples:

MSS = require('mos-mss');
client = new MSS({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>',
bucket: 'Bucket'


result = client.deleteObject('ObjectKey');

lt.then(function (res) {
console.log(res);

Parameters:

Return:

deleteMultiple(keys[, options])

Deletes objects by query.

Examples:

MSS = require('mos-mss');
client = new MSS({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>',
bucket: 'Bucket'


result = client.deleteMultiple('array');

lt.then(function (res) {
console.log(res);

Parameters:

Return:

signatureUrl(name[, options])

Examples:

MSS = require('mos-mss');
client = new MSS({
accessKeyId: '<accessKeyId>',
accessKeySecret: '<accessKeySecret>',
bucket: 'Bucket'


result = client.signatureUrl('ObjectKey');

lt.then(function (res) {
console.log(res);

Parameters:

Return:

License

MIT


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.