# uploadLocalFile ^7.8
通用上传本地文件
# 请求参数
Prop | Type | Default | Comment |
---|---|---|---|
domain | String | N/A | 服务器domain |
path | String | N/A | 服务器path |
filePath | String | N/A | 要上传文件资源的路径 (本地相对路径) WeexApp目录说明; |
timeout | String | N/A | 超时时间,单位为毫秒; |
fileKey | String | N/A | 数据关联的名称。原生在post表单中传输文件的key值,缺省默认值为“file”.。 |
netParam | String | N/A | [object Object],参考示例 |
imgParam | String | N/A | [object Object],参考示例 |
mimeType | String | N/A | 默认为application/octet-stream,上传图片为image/jpg |
# 接口调用示例
const params = {
domain: 'https://mp-sit.smartmidea.net/mas/v5/app/proxy?alias=', // 域名
path: '/ccrm2-core/uploadApi/upload', // path
filePath: 'xxx', //要上传文件资源的路径 (本地相对路径) WeexApp目录说明;
timeout: 'xxxx', //超时时间,单位为毫秒;
fileKey: 'xxx', // 数据关联的名称。原生在post表单中传输文件的key值,缺省默认值为“file”.。
netParam: {
a: 'xxx', //weex需要原生填充给服务器的post 表单参数1
b: 'xxx', // weex需要原生填充给服务器的post 表单参数2
},
imgParam: {
//如上传图片需要额外参数处理,此参数有值
maxWidth: '',
maxHeight: '',
compressRage: '',
},
mimeType: 'image/jpg', //默认为application/octet-stream,上传图片为image/jpg
}
// 注意 需要用callback而非promise方式调用。
this.$bridge
.uploadLocalFile(params, (res)=>{
this.$alert(res)
},(err)=>{
this.$alert(err)
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 接口返回示例
{
"status": 0,
"progress": "进度",
"data": "服务器返回的数据obj"
}
1
2
3
4
5
6
7
2
3
4
5
6
7
# FAQ
TIP
调用方式需要用callback而非promise方式,详细参考示例