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: '',
});参数说明
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
sourcePicture | PicBaseInfo | 是 | 原图资源信息。 |
bigPicture | PicBaseInfo | 是 | 大图资源信息。 |
snapshotPicture | PicBaseInfo | 是 | 缩略图资源信息。 |
sourcePath | string | 是 | 图片本地路径;只有远端资源时传空字符串。 |
每个 PicBaseInfo 包含 uuid、type、size、width、height 和 url,分别表示资源标识、类型、字节大小、像素尺寸和远端地址。调用后返回待发送的 MessageItem,发送时使用发送已上传的媒体消息。
这个页面有帮助吗?