# file-block-upload

> file-block-upload

Latest version **1.1.10** (published 2023-04-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install file-block-upload
pnpm add file-block-upload
yarn add file-block-upload
bun add file-block-upload
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.10 |
| Published | 2023-04-13 |
| First published | 2023-02-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 35.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | jason.han2199 |
| Keywords | react, file, chunk, block, upload |

## Links

- npm: https://www.npmjs.com/package/file-block-upload
- npm.io page: https://npm.io/package/file-block-upload

## Dependencies (1)

- [spark-md5](https://npm.io/package/spark-md5.md) ^3.0.2

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.1.10 (latest) — 2023-04-13
- 1.1.9 — 2023-04-12
- 1.1.8 — 2023-04-12
- 1.1.7 — 2023-04-12
- 1.1.6 — 2023-04-12
- 1.1.5 — 2023-04-11
- 1.1.4 — 2023-04-11
- 1.1.3 — 2023-04-11
- 1.1.2 — 2023-04-11
- 1.1.1 — 2023-04-11
- 1.1.0 — 2023-04-11
- 1.0.4 — 2023-03-01
- 1.0.3 — 2023-02-28
- 1.0.2 — 2023-02-24
- 1.0.1 — 2023-02-24
- … 1 more at https://npm.io/package/file-block-upload/versions

## README

## 一、安装

```shell
yarn add file-block-upload

npm install file-block-upload --save
```

## 二、示例

```ts
  import FileUpload from 'file-block-upload';

  const upload = file => {
    file.uid = "u101";
  
    const options = {
      threads: 10,
      extras: { id: 101},
      checkFile: async ({fileName, fileMd5, fileSize}: any) => {
        const result: {success: boolean, message: string, data: any } = await post('api/checkFile', { fileName, fileMd5, fileSize });
        return result
      }, 
      checkBlock: "api/checkBlock",
      uploadBlock: "api/uploadBlock",
  
      mergeBlock: "api/mergeBlock",
      mergeProgress: "api/mergeProgress",
  
      verifyFile: "api/verifyFile",
      verifyProgress: "api/verifyProgress",
    }
  
    const upload = FileUpload.create(options);
    upload.progress((file, progress) => {
      console.log(file, progress);
    });
    upload.complete(file => {
      console.log(file.response);
    });
    upload.error((file, error)=> {
      console.log(file.name, error);
    });
    upload.start(file);
  }
```


## 三、options 参数说明


### 属性


| 名称        | 说明                 | 类型    | 默认值 |
| ----------- | -------------------- | ------- | ------ | 
| threads       | 同时上传并发数量     | number  | 5 |
| blockSize   | 文件分片大小  | number | 10M   | 
| blockRetry   | 上传出错，重试次数 | number  | 3 | 
| extras       | 额外扩展字段 | object  | - | 




### 请求


| 名称         | 参数                 | 说明    |  默认值  | 
| ----------- | -------------------- | ------- | ------- | 
| checkFile | false 丨 string 丨 (CheckFile) => Promise&lt;boolean&gt; | 类型为`string`时，表示使用`POST`请求的`url`地址；类型为`function`时，自定义检查上传文件方法；   | false |
| checkBlock | false 丨 string 丨 (CheckBlock) => Promise&lt;boolean&gt; | 类型为`string`时，表示使用`POST`请求的`url`地址；类型为`function`时，自定义检查当前上传分片； | false |
| uploadBlock | false 丨 string 丨 (UploadBlock) => Promise&lt;void&gt; | 类型为`string`时，表示使用`POST`请求的`url`地址；类型为`function`时，自定义上传分片； | false |
| mergeBlock | false 丨 string 丨 ({fileName, fileMd5}) => Promise&lt;any&gt; | 类型为`string`时，表示使用`POST`请求的`url`地址；类型为`function`时，自定义检查合并分片； | false |
| mergeProgress | false 丨 string 丨 () => Promise&lt;number&gt; | 类型为`string`时，表示使用`GET`请求的`url`地址；类型为`function`时，自定义返回合并进度； | false |
| verifyFile | false 丨 string 丨 ({fileName, fileMd5}) => Promise&lt;any&gt; | 类型为`string`时，表示使用`POST`请求的`url`地址；类型为`function`时，自定义验证文件； | false |
| verifyProgress | false 丨 string 丨 () => Promise&lt;number&gt; | 类型为`string`时，表示使用`GET`请求的`url`地址；类型为`function`时，自定义返回验证进度； | false |



### 方法


| 名称   | 参数     | 说明   |
| ----------- | -------------------- | ------- |
| progress | number | 整体进度 |  
| complete | file | 文件上传完成 |  
| error | Exception | 捕获上传异常 |  
| start | file | 开始上传文件 |  




#### **参数**

**CheckFile**

| 参数 | 类型   | 说明                                         |
| ---- | ------ | ------------------------------------------- |
| fileName | string | 文件名称 |
| fileMd5 | string | 文件 `MD5` `HEX` |
| fileSize | number | 文件大小 |



**CheckBlock**

| 参数 | 类型   | 说明                                         |
| ---- | ------ | ------------------------------------------- |
| fileName | string | 文件名称 |
| fileMd5 | string | 文件 `MD5` `HEX` |
| blockMd5 | number | 文件分片 `MD5` `HEX` |
| blockIndex | number | 文件分片索引 |



**UploadBlock**

| 参数 | 类型   | 说明                                         |
| ---- | ------ | ------------------------------------------- |
| fileName | string | 文件名称 |
| fileMd5 | string | 文件 `MD5` `HEX` |
| blockMd5 | number | 文件分片 `MD5` `HEX` |
| blockIndex | number | 文件分片索引 |
| file | Blod | 分片文件二进制对象 |

---
_Source: https://npm.io/package/file-block-upload · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
