cmp-oss-plugin
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published
  1. 项目说明

    用于文件上传, 上传至各种厂商的对象存储,目前支持的尝试有, 腾讯云cos, 易企秀eofs.

  2. 引入方式

    2.1 引入依赖

    ​ "cmp-oss-plugin": "^1.1.0"

    2.2 安装

    ​ npm install

  3. 项目使用

    let CmpOssPlugin = require('cmp-oss-plugin');
    
    const opts = {
      serverHost: 'http://test.eqxiu.cn',
      assetHost: 'http://asset.eqxiu.cn'
    }
    let ossPlugin = new CmpOssPlugin(opts);
    // 直接上传
    ossPlugin.uploadFile(file).then(res => {
    	resolve(res);
    })
    
    // 获取token
    ossPlugin.getTempToken().then(res => {
    	resolve(res);
    })
    
    // 使用token上传
    ossPlugin.uploadUseToken(file, token).then(res => {
    	resolve(res);
    })
  4. 参数说明

    1. new CmpCosPlugin(options)

      options参数:

      serverHost: 服务域名,用于获取token, 例如:http://test.eqxiu.cn / https://www.eqxiu.cn

      assetHost: 资源域名, 用户资源访问, 例如: http://asset.eqxiu.cn / http://test-asset.eqxiu.cn

      fileType:文件类型,1代表图片, 传此参数, 上传后会返回图片的宽,高,大小

      onUploadProgress: 上传过程中会调用此方法

      onError: 上传失败调用此方法

      onFileUploaded: 上传结束调用此方法

    2. getPrefixToken(prefix: string, fileName: string, fileType: string)

      prefix: 文件目录,一般为用户id

      fileName: 文件名

      fileType: 文件后缀, 默认为png,可不传

    3. getTempToken(fileType: string = 'png')

      获取临时token, 有效期1小时

    4. getPreviewToken(fileType: string = 'png')

      获取临时token, 用于预览,链接有"preview"标识,有效期1小时

    5. uploadFile(file: File)

      上传文件, 内部会自动获取token

    6. uploadUseToken(file: File, token: object)

      上传文件, 使用自己获取的token

    7. uploadBase64UseToken(base64: string, token: any)

      上传文件(base64), 使用自己获取的token

    8. uploadBase64(base64: string, suffix: string)

      suffix: 文件后缀, 默认png

      上传文件(base64), 内部会自动获取token

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
2.0.20latest

Version History

VersionDownloads (Last 7 Days)Published
2.0.20
2.0.10
2.0.00
1.1.220
1.1.210
1.1.200
1.1.190
1.1.170
1.1.160
1.1.150
1.1.140
1.1.130
1.1.120
1.1.110
1.1.100
1.1.90
1.1.80
1.1.70
1.1.61
1.1.50
1.1.40
1.1.30
1.1.10
1.1.00
1.0.220
1.0.210
1.0.200
1.0.190
1.0.180
1.0.170
1.0.160
1.0.150
1.0.140
1.0.130
1.0.120
1.0.110
1.0.100
1.0.90
1.0.80
1.0.70
1.0.50
1.0.40
1.0.30
1.0.20
1.0.00

Package Sidebar

Install

npm i cmp-oss-plugin

Weekly Downloads

1

Version

2.0.2

License

ISC

Unpacked Size

3.19 MB

Total Files

15

Last publish

Collaborators

  • lonsy