跳到主要内容

createImageMessageByFile

功能介绍

说明

根据文件对象创建图片消息。

注意

仅 web 端支持

函数原型

IMSDK.createImageMessageByFile({
sourcePicture: PicBaseInfo;
bigPicture: PicBaseInfo;
snapshotPicture: PicBaseInfo;
sourcePath: string;
file: File;
}, operationID?: string): Promise<WsResponse<MessageItem>>

输入参数

参数名称参数类型是否必填描述
sourcePicturePicBaseInfo原图相关信息
bigPicturePicBaseInfo大图相关信息
snapshotPicturePicBaseInfo缩略图相关信息
sourcePathstring图片在本机的绝对路径,如果没有传空字符即可
fileFile文件对象

返回结果

参数名称参数类型描述
Promise.then()Promise<WsResponse<MessageItem>>调用成功回调
Promise.catch()Promise<WsResponse>调用失败回调

代码示例

import { getSDK } from 'open-im-sdk-wasm';
const IMSDK = getSDK();

// use in electron with ffi
// import { getWithRenderProcess } from '@openim/electron-client-sdk/lib/render';
// const { instance: IMSDK } = getWithRenderProcess();

// use in mini program
// import { OpenIMSDK } from 'open-im-sdk';
// const IMSDK = new OpenIMSDK();

const picBaseInfo = {
uuid: "uuid",
type: imageFile.type,
size: imageFile.size,
width: 1024,
height: 1024,
url: "",
}

IMSDK.createImageMessageByFile({
sourcePicture: picBaseInfo;
bigPicture: picBaseInfo;
snapshotPicture: picBaseInfo;
sourcePath: imageFile.path;
file: imageFile
})
.then(({ data }) => {
// 调用成功
})
.catch(({ errCode, errMsg }) => {
// 调用失败
});