Get the latest version from NPM:
npm install file-burst
Also available with yarn:
yarn add file-burst
import FileBurst from 'file-burst';
const Burst = new FileBurst(file, {
burstSize: 10 * 1024, // 每片大小 (10M)
uploadAbortCallBack: function (e) {
console.log(`被打断请求信息:`, e);
}, // 请求函数被打断回调
data: {}, // 网络请求参数
name: "file", // 上传的文件字段名, 会放到请求体
uploadUrl: "", // 网络请求地址
progressCallBack: function (percentage, index) {
console.log(`当前进度:${percentage}; 当前上传第${index + 1}个文件`);
}, // 请求进度回调
headerConfig: {}, // 设置请求头
});
const upload = Burst.upload(); // 发送请求
upload.abort(); // 请求终止
upload.then((res) => { // 最终请求完成返回
console.log(res); // response body
}).catch((e) => {
console.log(e);
});
param | require | type | default |
---|---|---|---|
burstSize | false | Number | 10 * 1024 * 1024 |
name | false | String | file |
uploadUrl | false | String | "" |
data | false | Object | {} |
headerConfig | false | Object | {} |
uploadAbortCallBack | false | Function | Function() {} |
progressCallBack | false | Function | Function() {} |
only me
[ISC]