uploadImage(params: Object)

版本要求:
BizKit≥3.0.0@ray-js/ray≥0.3.23
支持平台:
iOS
import { uploadImage } from '@ray-js/ray';

// Promise 调用
try {
  const res = await uploadImage({ ...params });
  console.log(res);
} catch (err) {
  console.log(err.errorMsg);
}

描述

上传图片文件

参数

属性类型必填默认值说明
filePathstring是-图片文件路径
bizTypestring是-business type, get from cetus:scene alias, if not exist, please create it 业务场景标识,对应 Cetus 配置的场景别名;未配置时需要先创建上传场景
contentTypestring否-文件 MIME 类型,iOS 必传,例如 image/jpeg
delayTimenumber否2.0大文件上传结果轮询间隔,单位秒,默认 2 秒
pollMaxCountnumber否5大文件上传结果最大轮询次数,默认 5 次
complete() => void否-接口调用结束的回调函数(调用成功、失败都会执行)
success(params: Object) => void否-接口调用成功的回调函数
fail(params: Object) => void否-接口调用失败的回调函数
success 回调参数
属性类型说明BizKit 最低版本
resultstring上传接口返回的 JSON 字符串v3.1.2
fail 回调参数
属性类型说明
errorMsgstring错误信息
errorCodestring | number错误码
错误扩展

返回值

无

示例代码

import { downloadFile, uploadImage } from '@ray-js/ray'

// Download a real image to a local path first, then upload it.
// bizType is a cetus web_file_scene alias configured on the backend (e.g. "light-common").
downloadFile({
  url:
    "https://images.tuyacn.com/rms-static/b7bed040-87b8-11eb-864d-a9f07cbbdf37-1616051299140.png?tyName=logo_cn.png",
  success: res => {
    const filePath = res.tempFilePath || res.filePath || res.apFilePath;
    console.log("downloaded", filePath);
    uploadImage({
      filePath: filePath,
      bizType: "light-common",
      contentType: "image/png",
      delayTime: 2,
      pollMaxCount: 5,
      success: data => {
        console.log(data);
      },
      fail: error => {
        console.error(error);
      },
    });
  },
  fail: error => {
    console.error(error);
  },
});