SDKsWASM
使用 URL 创建图片消息
使用 WASM SDK 从已上传图片信息创建图片消息。
当图片已通过业务后台或第三方对象存储(如阿里云 OSS、腾讯云 COS、AWS S3)完成上传并取得公网 URL 时,可调用 createImageMessageByURL() 直接构建图片消息:
参数说明
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
sourcePicture | Picture | 是 | 原图信息。 |
bigPicture | Picture | 是 | 大图信息。 |
snapshotPicture | Picture | 是 | 缩略图信息。 |
sourcePath | string | 是 | 原始文件的本地名称或业务路径;只有远端资源时传空字符串。 |
三个 Picture 参数使用相同的字段结构:
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
Picture.uuid | string | 是 | 图片资源的唯一标识。 |
Picture.type | string | 是 | 图片 MIME 类型。 |
Picture.size | number | 是 | 图片大小,单位为字节。 |
Picture.width | number | 是 | 图片宽度,单位为像素。 |
Picture.height | number | 是 | 图片高度,单位为像素。 |
Picture.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: '',
});接口调用成功后返回待发送的 MessageItem 对象。由于图片资源已预先上传完成,后续需使用 发送已上传的媒体消息(sendMessageNotOss)发送该消息。
这个页面有帮助吗?