gs-multipart-upload
v0.0.2
Published
gs 断点续传插件
Downloads
7
Readme
断点续传
功能概述
- 存储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字段选择的接口地址||
