# lmw-uploader

> uploader

Latest version **1.0.5** (published 2017-06-29) · ISC license · 0 weekly downloads

## Install

```sh
npm install lmw-uploader
pnpm add lmw-uploader
yarn add lmw-uploader
bun add lmw-uploader
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.5 |
| Published | 2017-06-29 |
| First published | 2017-06-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | lmw6412036 |
| Maintainers | lmw6412036 |
| Keywords | uploader |

## Links

- npm: https://www.npmjs.com/package/lmw-uploader
- Repository: https://github.com/lmw6412036/uploader
- Homepage: https://github.com/lmw6412036/uploader#readme
- Issues: https://github.com/lmw6412036/uploader/issues
- npm.io page: https://npm.io/package/lmw-uploader

## Recent versions

- 1.0.5 (latest) — 2017-06-29
- 1.0.4 — 2017-06-29
- 1.0.3 — 2017-06-28
- 1.0.2 — 2017-06-28

## README

# uploader

基础上传函数

## 安装

```bash
npm i -S lmw-uploader
```

## 使用

```bash
let Upload from 'lmw-uploader'//函数返回promise对象
Upload(filelist, {
          server: "",
          fileVal: "file",
          formData: {name: "lmw"},
          clearQueue: false,
          progress: (res, file) => {
            
          },
          queued: (file) => {
            
          },
          success: (res, file) => {
            
          },
          complete: (res) => {
            
          },
          error: (res) => {
            
          }
        });
```

## API

#### files 文件对象列表

#### options Object
###### options.headers {Object} [可选] [默认值：{}] http 请求的header
###### options.formData  {Object} [可选] [默认值：{}] 文件上传请求的参数表，每次发送都会发送此对象中的参数。
###### options.fileVal {String} [可选] [默认值：'file'] 设置文件上传域的name。

###### options.server {String} [必填] 设置服务器上传地址。

###### options.clearQueue {Boolean} 上传结束后是否清空上传队列，清空后可重复上传一个文件

#### 回调函数
###### options.progress {target,file} 进度状态，文件对象
```angular2html
progress: (res, file) => {
            this.pics.forEach((pic, index) => {
              if (pic.fileId && pic.fileId == file.fileId) {
                let f = Object.assign({}, file, {
                  progress: (res.loaded / res.total * 100).toFixed(2) + "%"
                })
                this.pics.splice(index, 1, f);
              }
            })
          }
```

###### options.queued {file} 文件添加到队列后
```angular2html
queued: (file) => {
            //console.log("add file", file);
            //this.queueFiles.push(file);
            this.pics.push(file);
          }
```
###### options.success {res,file} 文件上传成功回调
```angular2html
success: (res, file) => {
            this.pics.forEach((pic, index) => {
              if (pic.fileId && pic.fileId == file.fileId) {
                let f = Object.assign({}, file, {
                  //修改url为上传后的返回结果
                })
                this.pics.splice(index, 1, f);
              }
            })
          }
```
###### options.complete {Array} 队列所有文件上传成功后回调，数组元素是每个文件上传成功后服务器返回的对象
```angular2html
complete: (res) => {
            //console.log("complete", res);
            //this.queueFiles.splice(0, this.queueFiles.length);
          }
```
###### options.error {Object|String} 队列处理失败回调

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