createFileMessageByFile
Feature Introduction
Description
Create a file message.
Note
Only supported on the web platform. It's recommended not to use it for large file uploads. For uploading files larger than 1G, it's advised to use the createFileMessageByURL interface.
- Browser/Electron/MiniProgram
Function Prototype
IMSDK.createFileMessageByFile({
filePath: string;
fileName: string;
uuid: string;
sourceUrl: string;
fileSize: number;
fileType: string;
file: File;
}, operationID?: string): Promise<WsResponse<MessageItem>>
Input Parameters
Parameter Name | Parameter Type | Mandatory | Description |
---|---|---|---|
filePath | string | Yes | The absolute path of the file, use an empty string if not available |
fileName | string | Yes | File name |
uuid | string | Yes | Unique file ID |
sourceUrl | string | Yes | Just use an empty string |
fileSize | number | Yes | File size |
fileType | string | Yes | File type |
file | File | Yes | File object |
Return Result
Parameter Name | Parameter Type | Description |
---|---|---|
Promise.then() | Promise<WsResponse<MessageItem>> | Successful callback |
Promise.catch() | Promise<WsResponse> | Failed 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 { OpenIMSDK } from 'open-im-sdk';
// const IMSDK = new OpenIMSDK();
IMSDK.createFileMessageByFile({
filePath: videoFile.path || '',
fileName: videoFile.name,
uuid: 'uuid',
sourceUrl: '',
fileSize: videoFile.size,
fileType: videoFile.type,
file: videoFile,
})
.then(({ data }) => {
// Success callback
})
.catch(({ errCode, errMsg }) => {
// Error callback
});