@szgc/upload
v1.0.2
Published
## 使用
Downloads
6
Readme
<数分> 搭配平台的分片上传及续传组件
使用
import { Upload } from "@szgc/upload";
// 文件上传
Upload.create(option : UploadOption);
// 文件续传
Upload.create(request_id : string, option: UploadOption);
/**
* 文件上传参数
*/
interface UploadOption {
/**
* 文件
*/
target: File;
/**
* 业务id,非必填,默认为当前时间戳
*/
businessId?: string;
/**
* 功能id,非必填
*/
functionId?: string;
/**
* 文件切割参数,size:默认 [ 50M ];divide:默认 [ 10份 ]
*/
size?: number;
/**
* 上传开始事件
*/
onStart?: UploadEventCallback;
/**
* 上传完成事件
*/
onEnd?: UploadEventCallback;
/**
* 上传中事件
*/
onProgress?: UploadEventCallback;
/***
* 错误事件
*/
onError?: UploadEventCallback;
}
// 上传回调事件
type UploadEventCallback = (data: UploadEvent) => void;
interface UploadEvent {
/**
* 上传文件总大小
*/
total: number;
/**
* 信息,续传时会用到
*/
message: string;
/**
* 已上传总大小
*/
loaded: number;
/**
* 当前上传速度,byte / s
*/
speed: number;
/**
* 总体下载任务的状态
*/
state: "pending" | "resolved" | "rejectd";
/**
* 所有的文件片段
*/
chunks: Array<{
name: string;
request_id: string;
md5_hash: string;
index: number;
state: "pending" | "resolved" | "rejected";
loaded: number;
total: number;
}>;
}