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

Create an image message from a URL

Construct a pending image message from existing remote image URLs and metadata.

Copy

Invoke createImageMessageByURL() when image files have already been uploaded to your application server or content delivery network, avoiding the SDK's built-in file upload workflow.

Parameters

ParameterTypeRequiredDescription
sourcePathstringNoOriginal local file path; pass an empty string "" when only remote URLs exist.
sourcePictureOpenIMPictureYesInformation regarding the original high-resolution image asset.
bigPictureOpenIMPictureYesInformation regarding the display preview image asset.
snapshotPictureOpenIMPictureYesInformation regarding the thumbnail preview image asset.

Each OpenIMPicture object contains the following fields:

FieldTypeDescription
uuidstringUnique asset identifier returned by the upload service.
typestringMIME type of the image (for example, 'image/jpeg').
sizenumberFile size in bytes.
widthnumberImage width in pixels.
heightnumberImage height in pixels.
urlstringPublicly accessible remote URL of the image.

Code example

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

const picture = {
  uuid: uploaded.uuid,
  type: 'image/jpeg',
  size: uploaded.size,
  width: 1280,
  height: 720,
  url: uploaded.url,
}

const message = await createImageMessageByURL({
  sourcePath: '',
  sourcePicture: picture,
  bigPicture: picture,
  snapshotPicture: picture,
})
if (message == null) return

All dimensions, sizes, and URLs must reflect actual server upload responses.

Return value

The Promise resolves with an OpenIMMessageItem | null object.

State changes after the call

Pass the returned message item to Send a non-OSS message to transmit the payload without re-uploading the file. Track message state using clientMsgID.