浏览 SDKs · WASM
SDKsWASM

使用 URL 创建图片消息

使用 WASM SDK 从已上传图片信息创建图片消息。

复制

createImageMessageByURL() 使用已经上传的图片信息创建消息。原图、大图和缩略图可以指向不同资源;示例仅在三者相同时复用同一个对象。

参数说明

参数类型是否必填说明
sourcePicturePicBaseInfo原图信息。
bigPicturePicBaseInfo大图信息。
snapshotPicturePicBaseInfo缩略图信息。
sourcePathstring原始文件的本地名称或业务路径;只有远端资源时传空字符串。

三个 PicBaseInfo 参数使用相同的字段结构:

参数类型是否必填说明
PicBaseInfo.uuidstring图片资源的唯一标识。
PicBaseInfo.typestring图片 MIME 类型。
PicBaseInfo.sizenumber图片大小,单位为字节。
PicBaseInfo.widthnumber图片宽度,单位为像素。
PicBaseInfo.heightnumber图片高度,单位为像素。
PicBaseInfo.urlstring已上传图片的可访问地址。
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()