将本地资源上传到服务器。
| 属性 | 类型 | 默认值 | 必填 | 说明 |
| url | String | | 是 | 开发者服务器地址 |
| filePath | String | | 否 | 要上传文件资源的路径 (本地路径) |
| name | String | | 否 | 文件对应的 key,开发者在服务端可以通过这个 key 获取文件的二进制内容 |
| files | [Object] | | 否 | 多个文件对象的数组,优先级高于filePath, name |
| header | Object | | 否 | HTTP 请求 Header |
| formData | Object | | 否 | HTTP 请求中其他额外的 form data |
| timeout | Number | | 否 | 超时时间,单位为毫秒 |
| success | Function | | 否 | 接口调用成功的回调函数 |
| fail | Function | | 否 | 接口调用失败的回调函数 |
| complete | Function | | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
Object.files
| 属性 | 类型 | 默认值 | 必填 | 说明 |
| name | String | | 是 | 文件对应的 key ,开发者在服务端可以通过这个 key 获取文件的二进制内容 |
| filePath | String | | 是 | 要上传文件资源的路径 (本地路径) |
| 属性 | 类型 | 说明 |
| data | String | 开发者服务器返回的数据 |
| statusCode | Number | 开发者服务器返回的 HTTP 状态码 |
示例代码:
//上传单个文件
mc.chooseImage({
success: function(res){
mc.uploadFile({
url: 'https://test.com/upload',
filePath: res.tempFilePaths[0],
name: 'file',
formData: {
customA: '1',
customB: '2'
}
})
}
})
//上传多个文件
mc.chooseImage({
count: 3,
success: function(res){
var files = [];
for(var i in res.tempFilePaths){
files.push({
name: 'file' + i,
path: res.tempFilePaths[i]
})
}
mc.uploadFile({
files: files
})
}
})