# ulearning-obs

> obs

Latest version **0.0.64** (published 2026-08-14) · ISC license · 0 weekly downloads

## Install

```sh
npm install ulearning-obs
pnpm add ulearning-obs
yarn add ulearning-obs
bun add ulearning-obs
```

## Health

**Score 55/100 (C)** — status: active.

Positive: no vulnerabilities; recently updated; high maintenance score.

Warnings: low downloads; no types; no esm support; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.0.64 |
| Published | 2026-08-14 |
| First published | 2021-09-16 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 634.5 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | ulearning |
| Maintainers | liuzhong, ulearning_npm |
| Keywords | obs, qiniu, international, huawei |

## Links

- npm: https://www.npmjs.com/package/ulearning-obs
- npm.io page: https://npm.io/package/ulearning-obs

## Dependencies (3)

- [vue](https://npm.io/package/vue.md) ^2.6.14
- [qiniu-js](https://npm.io/package/qiniu-js.md) ^3.3.3
- [esdk-obs-browserjs](https://npm.io/package/esdk-obs-browserjs.md) ^3.22.3

## Alternatives

- [messageformat](https://npm.io/package/messageformat.md) — 329.7K weekly downloads
- [@mintlify/scraping](https://npm.io/package/@mintlify/scraping.md) — 294.8K weekly downloads
- [@mintlify/previewing](https://npm.io/package/@mintlify/previewing.md) — 209.5K weekly downloads
- [@mintlify/prebuild](https://npm.io/package/@mintlify/prebuild.md) — 209.5K weekly downloads
- [@mintlify/link-rot](https://npm.io/package/@mintlify/link-rot.md) — 206.3K weekly downloads

## Recent versions

- 0.0.64 (latest) — 2026-08-14
- 0.0.63 — 2026-07-17
- 0.0.62 — 2026-07-16
- 0.0.61 — 2026-07-16
- 0.0.60 — 2026-07-16
- 0.0.59 — 2024-10-18
- 0.0.58 — 2024-09-10
- 0.0.57 — 2024-09-10
- 0.0.56 — 2024-09-06
- 0.0.55 — 2024-09-06
- 0.0.54 — 2024-08-09
- 0.0.53 — 2024-05-09
- 0.0.52 — 2024-04-28
- 0.0.51 — 2024-04-15
- 0.0.50 — 2024-01-02
- … 47 more at https://npm.io/package/ulearning-obs/versions

## README

# ulearning-obs

#### 介绍
优学院文件服务obs，上传，下载等

#### 软件架构
javascript 依赖华为obs以及七牛云sdk


#### 安装教程

1.  npm i ulearning-obs

#### 使用说明

支持全局引入 amd cmd es6  dist目录输出两个版本的工具类 obs-huawei.js obs-qiniu.js分别对应华为云和七牛云

```
const Obs = require('ulearning-obs')
//or
import Obs from 'ulearning-obs'
//or
<script src="node_modules/ulearning-obs/dist/obs-huawei.js"></script>
```

## 使用
* new Obs({fileTypes?: Array, mode?: string, maxSize?: number, exts?: string, multiple?: Boolean,uptokenHost,m3u8?: Boolean})
    * fileTypes Array 文件类型 document image video audio zip flash srt 优学院对应文件类型格式,不传该字段默认支持全部文件类型
    * maxSize 文件最大限制 单位mb 默认1024
    * exts 扩展名doc,doc,xls等 多个用','隔开 覆盖type对应的扩展名
    * multiple 文件选择是否支持多选 true or false
    * errorCode 50001 文件类型不支持 50002 文件大小不符合 50070 七牛云token获取失败 50071七牛上传时失败 50080 华为token获取失败 50081华为上传时失败 50082 文件编码无法解析
    * uptokenHost 获取上传token的接口host 决定传到哪个服务器 cn app net ex:https://courseapi.tongshike.cn
    * m3u8 视频文件是否需要转码成m3u8格式（默认转码成MP4格式，如果此参数为true 会额外转码一份m3u8格式文件，回调的file文件会增加m3u8Key属性，值为转码后的m3u8文件路径）
    * authorization 上传接口权限校验（优学院账号）
    * obsSign 非优学院账号使用签名校验权限
    * obsHost 上传后文件的访问域名 七牛云上传的时候需要传此参数 华为云上传不需要 ex:https://leicloud.ulearning.cn
```
let obs = new Obs({
  maxSize: 10,
  fileTypes: [],
  multiple: true
})
```

* obs.initUpBtn(dom: dom) 给目标dom绑定文件选择上传
```
obs.initUpBtn(document.getElementById('uploaderBtn'))
```

* 监听函数 obs实例可绑定用于文件上传的监听事件
    * onBeforeUpload
    * onError
    * onSuccess
    * onProgress
```
obs.onBeforeUpload = function (file) {
  console.log('onBeforeUpload----',file)
    file.onProgress = function (percent) {
      console.log('progress----file-----' + percent)
    }
    file.onSuccess = function () {
      console.log('success----file-----')
    }
    file.onError = function (err) {
      console.log('error----file-----' + err)
    }
}
obs.onError = function (file,err) {
  console.log('error',file,err)
}
obs.onSuccess = function (file) {
  console.log('success----',file)
}
obs.onProgress = function (file,percent) {
  console.log('progress----',file, percent)
}
```
* obs.startUpload(file:File or Blob) 上传文件函数 支持File,Blob
  file(or blob)对象需要指定ext参数用于确定文件类型
```
file.ext = '.png'
obs.startUpload(file) or
obs.startUpload(blob)
```
* obs.cancelUpload(file:Object) 取消上传
```
obs.cancelUpload(uploader.files[0])
```
* obs.download(path,name) 下载文件，path:传入文件路径的全路径   name:下载后的文件名称 ex:abc.png 不传默认用key作为名字
```
obs.download('https://tongshike.obs.cn-north-4.myhuaweicloud.com/resources/web/16371358301228191.png')
```
####  0.0.17
增加音频默认转成流程（暂未开启）
####  0.0.25
转码源文件path路径处理(去除域名)
#### 0.0.26 
增加说转码失败code 50082
### 0.0.28
默认文件改为obs-qiniu.js  download参数拼接优化 

### 0.0.30
去除eval方法

### 0.0.31
华为云上传文件访问域名从后台直接获取domain

### 0.0.32
上传文件音视频增加duration参数

### 0.0.33
startUpload支持duration

### 0.0.34
音视频duration,从华为mpc获取

### 0.0.35 
七牛file.key赋值错误修复

### 0.0.36 
处理host多余斜杠 mp4转码失败正常走成功回调  提供新的qiniuUploadByToken方法，用于业务端自行获取token再进行上传

### 0.0.37
m3u8key以及转code=2修改

### 0.0.38
重新实现了download方法

### 0.0.39
without-polyfill

### 0.0.40
优化时长获取

### 0.0.41
时长获取回调bug修复

### 0.0.42
下载修改

### 0.0.43
下载方法重构

### 0.0.43
中文名下载bug
### 0.0.45
文件下载mp4格式

### 0.0.46
新增obs-nxu.js，宁夏大学本地部署定制

### 0.0.47
修改qiniu版本，自定义file key

### 0.0.48
增加obsSign参数，非优学院账号使用此签名参数获取上传下载配置

### 0.0.49
mp3增加转码（后台根据编码格式判断是否需要转码）

### 0.0.50
增加getDownloadUrl(path,name,callback)方法,和download类似,获取url是异步的需多传入一个回调函数

### 0.0.51
新增obs-cdp.js，宁夏大学本地部署定制

### 0.0.52
新增文档类型pps

### 0.0.53
新增obs-zuel.js，中南财大本地部署定制

### 0.0.54
新增7z xmind psd dwg格式文件

### 0.0.55
新增分段上传功能

### 0.0.56
修复分段上传的文件未返回obsHost问题

### 0.0.57
增加isMediaLengthNotNeeded参数 是否不获取视频时长

### 0.0.58
isMediaLengthNotNeeded bugfix

### 0.0.59
如果有预览地址，上传文件后直接从接口获取预览地址

### 0.0.60
isVideoTranscodeNotNeeded 新增参数 是否视频不需要转码

### 0.0.61
下载接口新增token

### 0.0.62
更新README.md

### 0.0.63
下载接口新增token build

---
_Source: https://npm.io/package/ulearning-obs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
