0.0.2 • Published 6 years ago

gs-multipart-upload v0.0.2

Weekly downloads
-
License
ISC
Repository
gitlab
Last release
6 years ago

断点续传

功能概述

  • 存储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 参数

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

6 years ago

0.0.1

6 years ago