SDKsWASM
Create an image message from a URL
Create an image message from uploaded image information with the WASM SDK.
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
| Parameter | Type | Required | Description |
|---|---|---|---|
sourcePicture | PicBaseInfo | Yes | Source image information. |
bigPicture | PicBaseInfo | Yes | Large image information. |
snapshotPicture | PicBaseInfo | Yes | Thumbnail information. |
sourcePath | string | Yes | Local 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:
| Parameter | Type | Required | Description |
|---|---|---|---|
PicBaseInfo.uuid | string | Yes | Unique identifier for the image resource. |
PicBaseInfo.type | string | Yes | Image MIME type. |
PicBaseInfo.size | number | Yes | Image size in bytes. |
PicBaseInfo.width | number | Yes | Image width in pixels. |
PicBaseInfo.height | number | Yes | Image height in pixels. |
PicBaseInfo.url | string | Yes | Accessible 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().
Was this page helpful?