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 🙏

© 2026 – Pkg Stats / Ryan Hefner

we-cloud-js

v1.0.1

Published

基于Wecloud API 开发的前端 JavaScript SDK

Downloads

0

Readme

Wecloud-JavaScript-SDK

基于Wecloud API 开发的前端 JavaScript SDK

当前版本为 1.x

快速导航

概述

Wecloud-JavaScript-SDK 为客户端 SDK,没有包含 token 生成实现,为了安全,token 建议通过网络从服务端获取,具体生成代码可以参考服务端 SDK 的文档。

功能简介

  • 上传
    • 文件上传
    • 图片上传

准备

  • JS-SDK 依赖服务端颁发 token,可以通过以下二种方式实现:

    前端通过接口请求以获得 token 信息

引入

支持以下几种安装方式

  • 直接使用静态文件地址:

    静态文件地址-暂无

    通过sctipt标签引入该文件,会在全局生成名为 Wecloud 的对象

  • 使用 NPM 安装

    NPM 的全称是 Node Package Manager,是一个 NodeJS 包管理和分发工具,已经成为了非官方的发布 Node 模块(包)的标准。如果需要更详细的关于 NPM 的使用说明,您可以访问 NPM 官方网站,或对应的中文网站

    npm install wecloud-js
    const wecloud = require('wecloud-js')
    // or
    import * as wecloud from 'wecloud'
  • 通过源码编译

git clone git@https://github.com/shengqianlong/we-cloud-js-sdk.git,进入项目根目录执行 npm install ,执行 npm run build,即可在dist 目录生成 Wecloud.min.js

使用

wecloud.upload 返回一个 observable 对象用来控制上传行为,observable 对像通过 subscribe 方法可以被 observer 所订阅,订阅同时会开始触发上传,同时返回一个 subscription 对象,该对象有一个 unsubscribe 方法取消订阅,同时终止上传行为。

Example

文件上传:


const upload = wecloud.uploadSingleFile(file, bucketId, uploadToken, options)

const subscription = observable.subscribe(observer) // 上传开始
// or
const subscription = upload.subscribe(next, error, complete) // 这样传参形式也可以

subscription.unsubscribe() // 上传取消

API Reference Interface

wecloud.upload(file, bucketId, uploadToken, options): observable

  • observable: 为一个带有 subscribe 方法的类实例

    • observable.subscribe(observer)

      • observer: observer 为一个 object,用来设置上传过程的监听函数,有三个属性 nexterrorcomplete:

        const observer = {
          next(res){
            // ...
          },
          error(err){
            // ...
          },
          complete(res){
            // ...
          }
        }
        • next: 接收上传进度信息的回调函数,回调函数参数值为 object,包含字段信息如下:

          • total: 包含loadedtotalpercent三个属性:
            • total.loaded: number,已上传大小,单位为字节。
            • total.total: number,本次上传的总量控制信息,单位为字节,注意这里的 total 跟文件大小并不一致。
            • total.percent: number,当前上传进度,范围:0~100。
        • error: 上传错误后触发;参数 err 为一个包含 codemessageisRequestError 三个属性的 object

          • err.isRequestError: 用于区分是否 xhr 请求错误;当 xhr 请求出现错误并且后端通过 HTTP 状态码返回了错误信息时,该参数为 true;否则为 undefined
          • err.code: number,请求错误状态码,只有在 err.isRequestError 为 true 的时候才有效
          • err.message: string,错误信息,包含错误码,当后端返回提示信息时也会有相应的错误信息。
        • complete: 接收上传完成后的后端返回信息,具体返回结构取决于后端sdk的配置

      • subscription: 为一个带有 unsubscribe 方法的类实例,通过调用 subscription.unsubscribe() 停止当前文件上传。