createImageMessageByFile
Feature Introduction
Description
Create an image message.
Note
Only supported on the web platform.
- Browser/Electron/MiniProgram
 
Function Prototype
IMSDK.createImageMessageByFile({
  sourcePicture: PicBaseInfo;
  bigPicture: PicBaseInfo;
  snapshotPicture: PicBaseInfo;
  sourcePath: string;
  file: File;
}, operationID?: string): Promise<WsResponse<MessageItem>>
Input Parameters
| Parameter Name | Parameter Type | Mandatory | Description | 
|---|---|---|---|
| sourcePicture | PicBaseInfo | Yes | Information about the original image | 
| bigPicture | PicBaseInfo | Yes | Information about the larger image version | 
| snapshotPicture | PicBaseInfo | Yes | Information about the thumbnail image | 
| sourcePath | string | Yes | The absolute path of the image on the local machine, pass an empty string if not available | 
| file | File | Yes | File object | 
Return Results
| Parameter Name | Parameter Type | Description | 
|---|---|---|
| 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 { 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 }) => {
    // Success
  })
  .catch(({ errCode, errMsg }) => {
    // Error
  });