SDKsWASM
使用 URL 创建图片消息
使用 WASM SDK 从已上传图片信息创建图片消息。
createImageMessageByURL() 使用已经上传的图片信息创建消息。原图、大图和缩略图可以指向不同资源;示例仅在三者相同时复用同一个对象。
参数说明
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
sourcePicture | PicBaseInfo | 是 | 原图信息。 |
bigPicture | PicBaseInfo | 是 | 大图信息。 |
snapshotPicture | PicBaseInfo | 是 | 缩略图信息。 |
sourcePath | string | 是 | 原始文件的本地名称或业务路径;只有远端资源时传空字符串。 |
三个 PicBaseInfo 参数使用相同的字段结构:
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
PicBaseInfo.uuid | string | 是 | 图片资源的唯一标识。 |
PicBaseInfo.type | string | 是 | 图片 MIME 类型。 |
PicBaseInfo.size | number | 是 | 图片大小,单位为字节。 |
PicBaseInfo.width | number | 是 | 图片宽度,单位为像素。 |
PicBaseInfo.height | number | 是 | 图片高度,单位为像素。 |
PicBaseInfo.url | string | 是 | 已上传图片的可访问地址。 |
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: '',
});Promise 成功只创建待发送对象。资源已经上传时使用 sendMessageNotOss()。
这个页面有帮助吗?