Skip to main content

createImageMessageByFile

Feature Introduction

Description

Create an image message.

Note

Only supported on the web platform.

Function Prototype

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

Input Parameters

Parameter NameParameter TypeMandatoryDescription
sourcePicturePicBaseInfoYesInformation about the original image
bigPicturePicBaseInfoYesInformation about the larger image version
snapshotPicturePicBaseInfoYesInformation about the thumbnail image
sourcePathstringYesThe absolute path of the image on the local machine, pass an empty string if not available
fileFileYesFile object

Return Results

Parameter NameParameter TypeDescription
Promise.then()Promise<WsResponse<MessageItem>>Success callback
Promise.catch()Promise<WsResponse>Error callback

Code Sample

import { getSDK } from '@openim/wasm-client-sdk';
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 }) => {
// Success
})
.catch(({ errCode, errMsg }) => {
// Error
});