chunks-upload
v1.1.35
Published
chunks upload
Downloads
1
Readme
chunks upload
无任何依赖的大文件分片上传库,只需少量代码与所用前端框架(react,vue 等)响应式数据进行绑定即可。
install
npm i chunks-upload
use
以 vue 为例
import ChunkUpload from "chunks-upload";
import { initiateUpload, completeUpload } from "@/api";
export default ({
sliceSize = 50 * 1024 * 1024,
maxUploadNum = 2,
}: {
sliceSize?: number;
maxUploadNum?: number;
}) => {
const loading = ref(false);
const percentage = ref(0);
const chunksUpload = new ChunkUpload(initiateUpload, completeUpload, {
loading: (_loading) => {
loading.value = _loading;
},
percentage: (_percentage) => {
percentage.value = _percentage;
},
});
chunksUpload.setChunkSize(sliceSize);
chunksUpload.setMaxNum(maxUploadNum);
const onUpload = (file: File) => {
return chunksUpload.upload(file);
};
return {
loading,
percentage,
onUpload,
};
};