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.
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
| Parameter | Type | Description |
|---|---|---|
sourcePicture | OpenIMPicture or null | Original image metadata. |
bigPicture | OpenIMPicture or null | Large image metadata. |
snapshotPicture | OpenIMPicture or null | Thumbnail metadata. |
sourcePath | string or null | Local 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().
Was this page helpful?