Skip to main content

createImageMessageByFile

Description

info

Create an image message based on a file object.

Note

Only supported on the Web side.

Function Prototype

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

Input Parameters

Parameter NameParameter TypeRequiredDescription
sourcePicturePicBaseInfoYesOriginal image information
bigPicturePicBaseInfoYesLarge image information
snapshotPicturePicBaseInfoYesThumbnail information
sourcePathstringYesAbsolute path of the image on the local machine; if none, empty string is fine
fileFileYesFile object

Return Result

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

Code Example

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 { getSDK } from '@openim/client-sdk';
// const IMSDK = getSDK();

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 }) => {
// Call successful
})
.catch(({ errCode, errMsg }) => {
// Call failed
});