SDKsuni-app / uni-app x
使用 URL 创建图片消息
根据已经上传的图片资源信息创建待发送消息。
createImageMessageByURL() 适用于图片已经由业务上传服务取得远端 URL 的场景。原图、大图和缩略图可以使用不同资源;只有三者确实相同时才复用同一份信息。
参数说明
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
sourcePath | string | 否 | 原始本地路径;只有远端资源时传空字符串。 |
sourcePicture | OpenIMPicture | 是 | 原图信息。 |
bigPicture | OpenIMPicture | 是 | 大图信息。 |
snapshotPicture | OpenIMPicture | 是 | 缩略图信息。 |
每个图片对象应填写实际资源信息:
| 字段 | 类型 | 说明 |
|---|---|---|
uuid | string | 资源唯一标识,优先使用上传结果返回的值。 |
type | string | 图片 MIME 类型。 |
size | number | 文件大小,单位为字节。 |
width | number | 图片宽度,单位为像素。 |
height | number | 图片高度,单位为像素。 |
url | string | 已上传图片的可访问地址。 |
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资源 URL、类型、大小和尺寸必须来自实际上传结果。创建成功后使用发送已上传的媒体消息,避免再次进入 SDK 上传流程。
这个页面有帮助吗?