Browse SDKs · HarmonyOS
Platform
SDKsHarmonyOSEnterprise

Create image message from local file

Create an image message from local filesystem image paths accessible to the application.

Copy

sourcePath must point to a stable local path accessible to the native HarmonyOS application. The optional bigPath and snapshotPath specify high-resolution and thumbnail images respectively; when omitted, the SDK falls back to the original image.

Code example

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;

Parameters

ParameterTypeRequiredDescription
sourcePathstringYesLocal filesystem path to the original image.
bigPathstringNoOptional local filesystem path to a compressed or high-res image variant.
snapshotPathstringNoOptional local filesystem path to a thumbnail snapshot image.

Return value

Returns a Promise resolving to CreateImageMessageResp:

PropertyTypeDescription
messageIMMessageLocally instantiated image message object.

State changes after the call

Temporary paths may be purged by the system. If sending is deferred, copy files into persistent application sandbox storage first. Promise resolution creates the message object locally; calling Send message subsequently triggers upload and transmission by the SDK.