# uploadImgFile ^5.0.0

上传图片文件,调用一次,上传一份图片文件

# 调用方式

uploadImgFile(params)
1

返回 Promise,使用 then/catch 或 await 处理结果。 接收单个业务参数;是否需要传参按下方参数表约定,无业务参数时可省略。具体字段及返回数据由宿主原生约定。

# 请求参数

参数 类型 必填 默认值 说明
params Object Y — 上传参数对象,不接受第二、第三个回调参数
params.patch String N — 旧文档使用的本地图片路径字段,保留该拼写
params.url String N — 上传地址
params.maxWidth Number N 原图宽度 最大图片宽度
params.maxHeight Number N 原图高度 最大图片高度
params.compressRage Number N 100(旧文档约定) 压缩率,0~100;旧文档注明 iOS 不支持
params.fileKey String N 'file'(旧文档约定) 表单文件字段
params.netParam Object N — 附加上传参数,字段由原生端决定

# 接口调用示例

const params = { patch: '/path/to/photo.jpg', url: 'https://example.com/upload' }

this.$bridge.uploadImgFile(params)
  .then(res => {
    console.log(res)
  })
  .catch(error => {
    console.error(error)
  })
1
2
3
4
5
6
7
8
9

# 返回参数

  • 成功时返回
Prop Type Default Description
progress Number 0~100 上传进度
msg String N/A 获取到服务器返回的消息内容
  • 失败时返回
Prop Type Default Description
errorCode Number N/A 上传失败后,服务器返回的错误码,例如404
errorMessage String N/A 错误消息(如有)

# 注意事项

当前 intl 接口返回 Promise,不使用旧文档的 callback/callbackFail 位置参数。上传字段及平台差异由原生实现决定。