uploadImage(params: Object)

Requires:
BizKit≥3.0.0@ray-js/ray≥0.3.23
Platforms:
iOS
import { uploadImage } from '@ray-js/ray';

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

Description

Upload image file

Parameters

PropertyTypeRequiredDefaultDescription
filePathstringYes-Image file path
bizTypestringYes-Business scenario identifier, obtained from Cetus (scene alias); if it does not exist, create the upload scene first
contentTypestringNo-File MIME type; required on iOS, e.g., image/jpeg
delayTimenumberNo2.0Polling interval for large-file upload results, in seconds. Default: 2 seconds
pollMaxCountnumberNo5Maximum polling attempts for large-file upload results. Default: 5
complete() => voidNo-Completion callback (executed on both success and failure)
success(params: Object) => voidNo-Callback on successful API call
fail(params: Object) => voidNo-Failure callback
success callback parameters
PropertyTypeDescriptionBizKit Since
resultstringJSON string returned by the upload APIv3.1.2
fail callback parameters
PropertyTypeDescription
errorMsgstringError message
errorCodestring | numberError code
Error extension

Return Value

None

Examples

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);
  },
});