浏览 SDKs · HarmonyOS
平台
SDKsHarmonyOS商业版

使用本地图片创建消息

根据应用可访问的本地图片路径创建待发送消息。

复制

sourcePath 必须是 HarmonyOS 应用原生侧可读取的稳定路径。可选的 bigPath 和 snapshotPath 分别指定大图与缩略图;省略时 SDK 使用原图。

import sdk, { CreateImageMessageReq, CreateImageMessageResp } from '@openimsdk/imsdk';

const request: CreateImageMessageReq = {
  sourcePath: imagePath,
  bigPath: bigImagePath,
  snapshotPath: thumbnailPath,
};
const response: CreateImageMessageResp = await sdk.createImageMessage(request);
const message = response.message;

临时路径可能被系统清理,需要延后发送时先复制到应用沙箱中的持久位置。Promise 成功只在本地创建消息对象;后续调用 发送消息 由 SDK 上传图片并发送。