浏览 SDKs · React Native
SDKsReact Native

使用 URL 创建图片消息

OpenIM React Native SDK 使用 URL 创建图片消息。

复制

使用 createImageMessageByURL() 根据已上传图片的资源信息创建消息。原图、大图和缩略图可共用同一资源信息,也可按业务需要分别传入不同尺寸或质量的资源。

const picture = {
  uuid: 'image-001',
  type: 'image/jpeg',
  size: 120000,
  width: 1280,
  height: 720,
  url: 'https://www.example.com/picture.png',
};

const message = await OpenIMSDK.createImageMessageByURL({
  sourcePicture: picture,
  bigPicture: picture,
  snapshotPicture: picture,
  sourcePath: '',
});

参数说明

参数类型是否必填说明
sourcePicturePicBaseInfo原图资源信息。
bigPicturePicBaseInfo大图资源信息。
snapshotPicturePicBaseInfo缩略图资源信息。
sourcePathstring图片本地路径;只有远端资源时传空字符串。

每个 PicBaseInfo 包含 uuidtypesizewidthheighturl,分别表示资源标识、类型、字节大小、像素尺寸和远端地址。调用后返回待发送的 MessageItem,发送时使用发送已上传的媒体消息