Browse SDKs · uni-app / uni-app x
SDKsuni-app

Create an image message from a URL

OpenIM uni-app / uni-app x SDK guide for Create an image message from a URL.

Copy

createImageMessageByURL() creates a message from already uploaded image metadata. The source, large image, and thumbnail can use different resources; this example reuses one object only when all three are identical.

Parameters

ParameterTypeDescription
sourcePictureOpenIMPicture or nullOriginal image metadata.
bigPictureOpenIMPicture or nullLarge image metadata.
snapshotPictureOpenIMPicture or nullThumbnail metadata.
sourcePathstring or nullLocal name or business path; use an empty string for a remote-only resource.

Each picture object has nullable uuid, type, size, width, height, and url fields. Supply the real upload result for a complete, displayable message.

import { createImageMessageByURL } from '@/uni_modules/unix-openim-sdk'

const picture = {
  uuid: createBusinessUUID(),
  type: 'image/jpeg',
  size: 120000,
  width: 1280,
  height: 720,
  url: uploaded.url,
}
const message = await createImageMessageByURL({
  sourcePicture: picture,
  bigPicture: picture,
  snapshotPicture: picture,
  sourcePath: '',
})

URLs must be accessible to conversation participants, and dimensions, size, and type must match the real resource. Do not place local paths in URL fields. The Promise only creates an outgoing object; send an already uploaded image with sendMessageNotOss().