Browse SDKs · WASM
SDKsWASM

Create an image message from a URL

Create an image message from uploaded image information with the WASM SDK.

Copy

createImageMessageByURL() creates a message from image information for resources that have already been uploaded. The source image, large image, and thumbnail can point to different resources. The example reuses one object only because all three variants are identical in this case.

Parameters

ParameterTypeRequiredDescription
sourcePicturePicBaseInfoYesSource image information.
bigPicturePicBaseInfoYesLarge image information.
snapshotPicturePicBaseInfoYesThumbnail information.
sourcePathstringYesLocal filename or application-defined path of the source file. Pass an empty string when only a remote resource is available.

All three PicBaseInfo parameters use the same field structure:

ParameterTypeRequiredDescription
PicBaseInfo.uuidstringYesUnique identifier for the image resource.
PicBaseInfo.typestringYesImage MIME type.
PicBaseInfo.sizenumberYesImage size in bytes.
PicBaseInfo.widthnumberYesImage width in pixels.
PicBaseInfo.heightnumberYesImage height in pixels.
PicBaseInfo.urlstringYesAccessible URL of the uploaded image.
const picture = {
  uuid: crypto.randomUUID(),
  type: 'image/jpeg',
  size: 120000,
  width: 1280,
  height: 720,
  url: uploaded.url,
};
const { data: message } = await openimsdk.createImageMessageByURL({
  sourcePicture: picture,
  bigPicture: picture,
  snapshotPicture: picture,
  sourcePath: '',
});

When the Promise resolves, it has created only a pending message object. Because the resource has already been uploaded, send it with sendMessageNotOss().