Browse SDKs · HarmonyOS
Platform
SDKsHarmonyOSEnterprise

Create image message from URL

Create an image message from pre-uploaded image resource metadata.

Copy

Original, high-resolution, and thumbnail variants can reference different URLs. Reuse identical metadata only when all three images actually share the same asset.

Code example

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

const picture: PictureBaseInfo = {
  uuid: uploaded.uuid,
  type: 'image/jpeg',
  size: uploaded.size,
  width: 1280,
  height: 720,
  url: uploaded.url,
};
const request: CreateImageMessageByURLReq = {
  sourcePicture: picture,
  bigPicture: picture,
  snapshotPicture: picture,
};
const response: CreateImageMessageResp = await sdk.createImageMessageByURL(request);
const message = response.message;

Parameters

ParameterTypeRequiredDescription
sourcePicturePictureBaseInfoYesOriginal image metadata including URL, dimensions, and size.
bigPicturePictureBaseInfoYesHigh-resolution or compressed image variant metadata.
snapshotPicturePictureBaseInfoYesThumbnail image metadata.

Return value

Returns a Promise resolving to CreateImageMessageResp:

PropertyTypeDescription
messageIMMessageLocally instantiated image message object referencing remote URLs.

State changes after the call

URL, MIME type, size, and dimensions must originate from verified upload responses. sourcePath, bigPath, and snapshotPath inside PictureBaseInfo are optional and only needed if retaining local paths. Call Send message after creation; the SDK automatically recognizes pre-existing remote asset URLs.