npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

baidubce-sdk

v0.0.23

Published

baidu cloud engine node.js sdk

Downloads

40

Readme

baidubce-sdk

Baidu Cloud Engine Node.js SDK

  1. BS (Baidu Cloud Storage)
  2. BOS (Baidu Object Storage)
  3. BCC (Baidu Cloud Compute)
  4. BFR (Baidu Face Recognition)
  5. Media

http://bce.baidu.com/index.html

Install

npm i baidubce-sdk

Usage

createBucket

var bce = require('baidubce-sdk');

var config = {
    credentials: {
        ak: 'ak',
        sk: 'sk'
    },
    endpoint: 'http://10.105.97.15'
};
var bucket = 'this-is-a-bucket';

var client = new bce.BosClient(config);
client.createBucket(bucket)
    .then(function(response) {
        console.log(response);
    })
    .then(function() {
        return client.deleteBucket(bucket);
    })
    .catch(function(error) {
        console.error(error);
    });

putObject

常用接口:

  1. putObjectFromString
  2. putObjectFromFile
var bce = require('baidubce-sdk');

var config = {
    credentials: {
        ak: 'ak',
        sk: 'sk'
    },
    endpoint: 'http://10.105.97.15'
};

var bucket = 'this-is-a-bucket';
var key = 'hello_world.js';

var client = new bce.BosClient(config);
client.createBucket(bucket)
    .then(function() {
        return client.putObjectFromFile(bucket, key, __filename);
    })
    .then(function() {
        return client.getObjectMetadata(bucket, key);
    })
    .then(function(response) {
        console.log(response);
    })
    .catch(function(error) {
        console.error(error);
    });

multipartUpload

常用接口:

  1. initiateMultipartUpload
  2. uploadPartFromFile
  3. completeMultipartUpload
var Q = require('q');
var bce = require('baidubce-sdk');

var config = {
    credentials: {
        ak: 'ak',
        sk: 'sk'
    },
    endpoint: 'http://10.105.97.15'
};

var bucket = 'this-is-a-bucket';
var key = 'large_file';

var large_file = 'this/is/a/large/file/path';
var filesize = fs.lstatSync(large_file).size;

var upload_id = null;

var client = new bce.BosClient(config);
client.createBucket(bucket)
    .then(function() {
        return client.initiateMultipartUpload(bucket, key);
    })
    .then(function(response) {
        upload_id = response.body.uploadId;
        
        var left_size = filesize;
        var offset = 0;
        var part_number = 1;
        
        var defers = [];
        while (left_size > 0) {
            var part_size = Math.min(left_size, 5 * 1024 * 1024);
            defers.push(client.uploadPartFromFile(
                bucket, file, upload_id,
                part_number, part_size, large_file, offset
            ));

            left_size -= part_size;
            offset += part_size;
            part_number += 1;
        }
        
        return Q.all(defers);
    })
    .then(function(all_response) {
        var part_list = [];
        for (var i = 0; i < all_response.length; i ++) {
            var response = all_response[i];
            part_list.push({
                partNumber: i + 1,
                eTag: response.http_headers.etag
            });
        }
        return client.completeMultipartUpload(bucket, key, upload_id, part_list);
    })
    .then(function(response) {
        console.log(response)
    })
    .catch(function(error) {
        console.error(error);
    });

Browser Usage

Use the putObjectFromBlob api.

browserify -s baidubce-sdk index.js -o baidubce-sdk.bundle.js
var sdk = require('./baidubce-sdk.bundle');
var $ = require('jquery');

$('files').on('change', function (evt) {
    var file = evt.target.files[0];

    var client = new sdk.BosClient(getBOSConfig());
    var bucket = getBucket();
    var key = file.name;
    var blob = file;

    var ext = key.split(/\./g).pop();
    var mimeType = sdk.MimeType.guess(ext);
    if (/^text\//.test(mimeType)) {
        mimeType += '; charset=UTF-8';
    }
    var options = {
        'Content-Type': mimeType
    };
    var promise = client.putObjectFromBlob(bucket, key, blob, options);
    client._httpAgent._req.xhr.upload.onprogress = function (evt) {
        if (evt.lengthComputable) {
            $('#g_progress').val(evt.loaded / evt.total);
        }
    };
    promise.then(function (res) {
        $('#g_progress').val(1);
        var url = client.generatePresignedUrl(bucket, key)
        $('#g_url').html('<a href="' + url + '" target="_blank">下载地址</a>');
    })
    .catch(function (err) {
        console.error(err);
    });
});

Others

More api usages please refer