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

@mingto/huawei-obs-server

v1.0.28

Published

华为云OBS文件上传

Downloads

617

Readme

@mingto/huawei-obs-server

文件上传至华为云 OBS(对象存储服务)工具库,支持单文件上传和分片上传两种方式,能满足不同大小文件的上传需求。

特性

  • 🚀 双模式支持:单文件上传 + 分片上传,自动根据文件大小选择
  • 📊 进度监控:实时上传进度回调
  • 取消上传:支持随时取消上传操作
  • 🔧 灵活配置:支持自定义分片大小、分片阈值等参数
  • 📱 浏览器端支持:专为浏览器环境优化

安装

pnpm add @mingto/huawei-obs-server

快速开始

import huaweiObsServer from '@mingto/huawei-obs-server'

// 配置全局参数
huaweiObsServer.config({
  getToken: () => '用户的token',
  fileSplitThreshold: 1024 * 1024 * 5  // 5MB,超过此阈值使用分片上传
})

// 创建要上传的文件对象
const sourceFile = new File(['hello world'], 'hello.txt', { type: 'text/plain' })

// 创建上传实例
const uploadContext = huaweiObsServer.create({
  sourceFile,
  onProgress: (event) => {
    console.log(`上传进度: ${event.percent}%`)
  },
  onSuccess: (event) => {
    console.log('上传成功:', event.fileInfo)
  },
  onError: (error) => {
    console.error('上传失败:', error.code, error.message)
  }
})

// 取消上传
// uploadContext.abort()

API

全局配置

huaweiObsServer.config(options)

配置全局参数,支持以下参数:

| 参数 | 类型 | 必填 | 默认值 | 说明 | |------|------|------|--------|------| | getToken | () => string | 是 | 无 | 用于获取上传所需的 token,该 token 用于身份验证 | | fileSplitThreshold | number | 否 | 6MB | 文件大小分隔线,超过阈值使用分片上传 |

创建上传实例

huaweiObsServer.create(options)

创建上传实例,支持以下参数:

| 参数 | 类型 | 必填 | 默认值 | 说明 | |------|------|------|--------|------| | sourceFile | File | 是 | 无 | 要上传的文件对象 | | partSize | number | 否 | 5MB | 文件分片大小 | | onStart | () => void | 否 | () => {} | 上传开始时的回调 | | onProgress | (event) => void | 否 | () => {} | 上传进度回调,event.percent 表示百分比 | | onSuccess | (event) => void | ❌ | () => {} | 上传成功回调,event 包含 sourceFilefileInfo | | onError | (error) => void | ❌ | () => {} | 上传失败回调 | | onAbort | () => void | 否 | () => {} | 取消上传时的回调 | | onFinally | () => void | 否 | () => {} | 上传结束回调(无论成功或失败) |

取消上传

uploadContext.abort()

取消当前上传。

uploadContext.abort()

错误处理

上传过程中出现错误时,会抛出对应的 ObsError 对象,可通过 error.code 获取错误码。

| 错误码 | 描述 | |--------|------| | 10001 | 请求失败,请检查网络 | | 10022 | 切片上传文件初始化信息的临时 URL 获取失败 | | 10002 | 切片上传文件初始化信息获取失败 | | 10033 | 切片上传文件段的临时 URL 获取失败 | | 10003 | 切片上传文件段失败 | | 10055 | 合并文件段的临时 URL 获取失败 | | 10005 | 合并文件段失败 | | 10006 | 获取文件信息失败 | | 10009 | 单文件上传获取临时 URL 失败 | | 10099 | 单文件上传失败 | | 10007 | 文件上传取消失败 |

注意事项

  • 本工具库依赖 axios,请确保项目中已安装 axios,版本要求为 ^1.7.9
  • 请确保返回的 token 是有效的,否则可能导致上传失败
  • 上传大文件时,建议根据网络状况调整 partSizefileSplitThreshold 参数

许可证

MIT