SDKsuni-app
从 URL 创建图片消息
使用已上传图片的 elem 信息创建消息。
createImageMessageByURL() 使用已经上传的图片信息创建消息。原图、大图和缩略图可以指向不同资源;示例仅在三者相同时复用同一个对象。
参数说明
| 参数 | 类型 | 说明 |
|---|---|---|
sourcePicture | OpenIMPicture 或 null | 原图信息。 |
bigPicture | OpenIMPicture 或 null | 大图信息。 |
snapshotPicture | OpenIMPicture 或 null | 缩略图信息。 |
sourcePath | string 或 null | 原始文件的本地名称或业务路径;只有远端资源时传空字符串。 |
三个图片对象使用相同字段:uuid、type、size、width、height 和 url,均为可选值;创建完整可展示消息时应填写真实上传结果。
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: '',
})URL 必须能被消息参与者访问,尺寸、大小和类型要与真实资源一致,不要把本地路径填入 URL 字段。Promise 成功只创建待发送对象;资源已经上传时使用 sendMessageNotOss()。
这个页面有帮助吗?