gs-multipart-upload

0.0.2 • Public • Published

断点续传

功能概述

  • 存储js-sdk的上传功能基于H5 File API
  • 大于4M的文件采用分块上传,每4M一块
  • 分块上传时,支持断点续传

使用说明

html 代码

<body>
  <input type="file" id="file"/>
  <button onclick="myFunction()">上传</button>
  <button onclick="cancelFunction()">取消上传</button>
</body>

js 代码

import {uploadCancel,uploadFile} from 'gs-multipart-upload'
// 获取token
function getToken(){
    let token ='';
    //TODO
    
    return token
}
const base64progress = function base64progress(p) {
  console.log(p);
};
const getRes = function getRes(res) {
  if (res.status === 1) {
    console.info('上传成功', res);
  } else {
    console.info('上传失败', res);
  }
};
function myFunction() {
  let config = {
    authorization: getToken(),
    businessKey: 'TEST',
    file: document.getElementById('file').files[0],
    isProduction: true,
    progress: base64progress,
    result: getRes,
    needShortURL: false,
    url: ''
 };
  uploadFile(config);
}
function cancelFunction(){
    uploadCancel();
}

方法

方法名 描述
uploadFile 上传方法 通过参数配置不同类型
uploadCancel 取消上传

uploadFile 参数

方法名 类型 必填 说明 备注
authorization string 上传凭证,请求各自业务后端系统获取 。参考:存储服务API中的 "获取存储服务授权token" 部分
businessKey string 业务线代号,由业务线后端或存储小组确定
file Blob 对象 上传的文件
isProduction boolean 是否为生产环境,默认true
progress fuction 上传进度回调函数,参数为0-1的number类型值,1表示上传完成
result fuction 上传完成后执行的回调函数,参数为后端返回的信息
needShortURL boolean 决定是否生成短链,默认为false
url string 自定义的接口地址,优先级高于isProduction字段选择的接口地址

Readme

Keywords

Package Sidebar

Install

npm i gs-multipart-upload

Weekly Downloads

0

Version

0.0.2

License

ISC

Unpacked Size

465 kB

Total Files

19

Last publish

Collaborators

  • gaosi-fe