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

wcs-nodejs-sdk

v3.0.6

Published

网宿云存储NodeJs SDK

Downloads

261

Readme

wcs-nodejs-sdk

安装

  1. npm安装
npm install wcs-nodejs-sdk
  1. 手动安装 从GitHub站点下载源码后,到根目录执行。
npm install

使用

如使用npm安装,使用如下require指令

const wcs = require('wcs-nodejs-sdk');

let client = new wcs.wcsClient(config);

如使用手动安装,则require根目录下的index.js文件

const wcs = require('wcs-nodejs-sdk/index');

let client = new wcs.wcsClient(config)

配置

使用wcs-nodejs-sdk之前,您需要

  1. 拥有一对密钥,可在网宿云存储控制台查看
  2. 新建一个空间,可以网宿云存储控制台操作

执行完以上操作后,在您的项目中创建一个config文件,配置项及定义如下

var config = {
    AccessKey: '<YOUR ACCESS KEY>',         // 上传凭证,可在您控制台安全管理-->密钥管理中查询
    SecretKey: '<YOUR SECRET KEY>',         // 管理凭证,可在您控制台安全管理-->密钥管理中查询
    UploadDomain: '<YOUR UPLOAD DOMAIN>',   // 上传域名(无需http前缀),可在您控制台安全管理-->域名查询中查询
    MgrDomain: '<YOUR MGR DOOMAIN>',        // 管理域名(无需http前缀),可在您控制台安全管理-->域名查询中查询
    BlockSize: <分片上传块大小>,             // 默认为4194304(4M,建议不修改),需大于4M且为4M的整数倍,需为int型整数
    HttpTimeout: <http超时时间>,          // http超时时间,单位毫秒。默认120000(120秒),需为int型整数
};

module.exports = config;

文件上传-普通上传

普通上传在一次操作中将文件上传至网宿云存储,建议仅在文件小于20M时使用普通上传。

范例

const wcs = require('wcs-nodejs-sdk');
const config = require('./config');

let putPolicy = {
    scope: bucket+':'+key,
    deadline: '<deadline>',
};

let client = new wcs.wcsClient(config);
var callback = function(err, data, res) {
    console.log('callback');
    if (err) {
        console.log(err);
    }
    else {
        console.log(res.statusCode);
        console.log(wcs.utils.urlSafeBase64Decode(data));
    }
}

// 普通上传
let filePath = __dirname+'/test';
client.uploadByPath(filePath, putPolicy, null, callback);

文件上传-分片上传

  1. 当文件较大时,使用普通上传容易出现超时等上传异常。建议在文件大于20M时选择分片上传功能。
  2. 使用分片上传时可自定义分块大小,但配置的分块大小必须大于4M且为4M的整数倍。
  3. 使用分片上传时如指定文件保存上传记录,则上传中断后再次上传相同文件会启用断点续传功能。

范例

const wcs = require('wcs-nodejs-sdk');
const config = require('./config');

let putPolicy = {
    scope: bucket+':'+key,
    deadline: '<deadline>',
};

let client = new wcs.wcsClient(config);
var callback = function(err, data, res) {
    console.log('callback');
    if (err) {
        console.log(err);
    }
    else {
        console.log(res.statusCode);
        console.log(wcs.utils.urlSafeBase64Decode(data));
    }
}

// 分片上传进度回调
var progressCallback = function(readLength, fileSize) {
    console.log(readLength + '/' + fileSize + ' finished');
}

// 分片上传
let filePath = __dirname+'/test20M';

// 若不指定recordFile则不会启用断点续传功能
let recordFile = __dirname+'/resume.record';
client.resumeUploadByPath(filePath, putPolicy, {deadline:3, mimeType: 'application/text', progressCallback: progressCallback}, callback);

更多范例参考wcs-nodejs-sdk/demos