---
url: /api-proxy/network/upload/uploadFile.md
---
## [UploadTask](https://developers.weixin.qq.com/miniprogram/dev/api/network/upload/wx.uploadFile.html) mpx.uploadFile(Object object)

将本地资源上传到服务器。客户端发起一个 HTTPS POST 请求，其中 content-type 为 multipart/form-data

支持情况： 微信、支付宝

[参考文档](https://developers.weixin.qq.com/miniprogram/dev/api/network/upload/wx.uploadFile.html)

### 参数 {#parameters}

**Object object**

| 属性           | 类型     | 默认值 | 必填 | 说明                                                                                                                        | 最低版本 | 支付宝 |
| -------------- | -------- | ------ | ---- | --------------------------------------------------------------------------------------------------------------------------- | -------- | ------ |
| url            | string   |        | 是   | 开发者服务器地址                                                                                                           |          | ✓ |
| filePath       | string   |        | 是   | 要上传文件资源的路径 (本地路径)                                                                                            |          | ✓ |
| name           | string   |        | 是   | 文件对应的 key，开发者在服务端可以通过这个 key 获取文件的二进制内容                                                        |          | ✓ |
| header         | Object   |        | 否   | HTTP 请求 Header，Header 中不能设置 Referer                                                                                |          | ✓ |
| formData       | Object   |        | 否   | HTTP 请求中其他额外的 form data                                                                                            |          | ✓ |
| timeout        | number   |        | 否   | 超时时间，单位为毫秒                                                                                                       | 2.10.0   | ✓ |
| enableProfile  | boolean  | true   | 否   | 是否开启 profile。iOS 和 Android 端默认开启，其他端暂不支持。开启后可在接口回调的 res.profile 中查看性能调试信息。           | 3.5.0    | ✗ |
| enableHttp2    | boolean  | false  | 否   | 是否开启 http2                                                                                                             | 2.10.4   | ✗ |
| enableQuic     | boolean  | false  | 否   | 是否开启 Quic/h3 协议（iOS 微信目前使用 gQUIC-Q43；Android 微信在 v8.0.54 前使用 gQUIC-Q43，v8.0.54 开始使用 IETF QUIC，即 h3 协议；PC微信使用 IETF QUIC，即 h3 协议） | 2.10.4   | ✗ |
| success        | function |        | 否   | 接口调用成功的回调函数                                                                                                      |          | ✓ |
| fail           | function |        | 否   | 接口调用失败的回调函数                                                                                                      |          | ✓ |
| complete       | function |        | 否   | 接口调用结束的回调函数（调用成功、失败都会执行）                                                                            |          | ✓ |

**object.success 回调函数**

**参数**

**Object res**

### 返回值 {#return-value}

[UploadTask](https://developers.weixin.qq.com/miniprogram/dev/api/network/upload/wx.uploadFile.html)

### 示例代码 {#example-code}

```js
mpx.chooseImage({
  success (res) {
    const tempFilePaths = res.tempFilePaths
    mpx.uploadFile({
      url: 'https://example.weixin.qq.com/upload', //仅为示例，非真实的接口地址
      filePath: tempFilePaths[0],
      name: 'file',
      formData: {
        'user': 'test'
      },
      success (res){
        const data = res.data
        //do something
      }
    })
  }
})
```
