# wechat-formdata

> 在微信小程序中调用formdata

Latest version **0.1.1-beat.0** (published 2021-04-20) · ISC license · 0 weekly downloads

## Install

```sh
npm install wechat-formdata
pnpm add wechat-formdata
yarn add wechat-formdata
bun add wechat-formdata
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1-beat.0 |
| Published | 2021-04-20 |
| First published | 2021-04-20 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 2 |
| Unpacked size | 1007 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | jleemt |

## Links

- npm: https://www.npmjs.com/package/wechat-formdata
- Repository: https://github.com/Lijie0981/wx-formdata
- Homepage: https://github.com/Lijie0981/wx-formdata#readme
- Issues: https://github.com/Lijie0981/wx-formdata/issues
- npm.io page: https://npm.io/package/wechat-formdata

## Dependencies (2)

- [mime-types](https://npm.io/package/mime-types.md) ^2.1.30
- [parse-filepath](https://npm.io/package/parse-filepath.md) ^1.0.2

## Recent versions

- 0.1.1-beat.0 (latest) — 2021-04-20
- 0.1.1-beat.1 (beta.1) — 2021-04-20

## README

# wx-formdata
在小程序中使用formdata上传数据，可实现多文件上传

# 用法
跟浏览器中的FormData对象类似
引入js文件
```js
const FormData = require('./formData.js')
```
new一个FormData对象
```js
let formData = new FormData();
```
调用它的[append()](#formdataappend)方法来添加字段或者调用[appendFile()](#formdataappendfile)方法添加文件
```js
formData.append("name", "value");
formData.appendFile("file", filepath);
```
添加完成后调用它的[getData()](#formdatagetdata)生成上传数据，之后调用小程序的wx.request提交请求
```js
let data = formData.getData();
wx.request({
  url: 'https://接口地址',
  header: {
    'content-type': data.contentType
  },
  data: data.buffer,
});
```

# 成员函数
### FormData.append()
#### 语法
```js
formData.append(name, value);
```
#### 参数
| 参数名 | 描述 |
| :---------- | :-----------|
| name | value中包含的数据对应的表单名称 |
| value | 表单的值 |

### FormData.appendFile()
#### 语法
```js
formData.appendFile(name, filepath);
```
#### 参数
| 参数名 | 描述 |
| :---------- | :-----------|
| name | value中包含的数据对应的表单名称 |
| filepath | 文件路径 | 

### FormData.getData()
#### 语法
```js
let data = formData.getData();
```
#### 返回值对象属性
| 属性名 | 描述 |
| :---------- | :-----------|
| buffer | 表单数据的ArrayBuffer对象 |
| contentType | http请求Content-Type头部内容 |

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