1.0.2 • Published 2 years ago
web-upload v1.0.2
下载 | Install
npm i web-upload -S
注意 | Notice
只能在浏览器中使用, 同时, 您的浏览器应该要支持HTML5 Can only be used in a browser, and your browser should support HTML5 Can be used in
html
,vue
,react
,angular
,h5
演示 | Demo
<script src="./web-upload/index.js"></script>
<script>
let btn = document.getElementById('btn');
let wu = new WebUpload();
btn.addEventListener('click', async () => {
let list = await wu.upload('files', 'single');
console.log('list', list);
});
</script>
多文件上传 | Multi-file upload
let list = await wu.upload('files', 'single');
多文件上传-分片 | Multi-file upload - splitting
let list = await wu.upload('files', 'chunk');
文件夹上传 | Folder Upload
let list = await wu.upload('dir', 'single');
文件夹上传-分片 | Folder upload - splitting
let list = await wu.upload('dir', 'single');
分片大小 | Slice size
默认分片大小为2m Default slice size is 2m
let wu = new WebUpload({
chunkSize: 2 * 1024 * 1024 // 2m
});
let list = await wu.upload('files', 'chunk');
过滤文件 | Filter files
这里只的是过滤不需要上传的文件或切片 Here only the files or slices that do not need to be uploaded are filtered
let wu = new WebUpload({
// 要排除的文件或碎片
// Files or fragments to be excluded
removeFilesHash: ['hash001', 'hash002', 'hash003-1', 'hash003-2']
});
let list = await wu.upload('files', 'chunk');
哈希计算进度 | Hash calculation progress
如果我们想要得到文件的哈希计算进度, 可以在类实例化的时候进行以下配置 If we want to get the progress of the hash calculation of the file, we can configure the class at the time of instantiation as follows
let wu = new WebUpload({
// 哈希进度
// hash progress
hashRate: (progress) => {
console.log(progress);
}
});
let list = await wu.upload('files', 'chunk');