Skip to main content

createFileMessageByFile

Description

info

Create a file message based on a file object.

Note

Only supported on the Web side, and it is best not to use it for large file uploads. For files larger than 1G, it is recommended to use the createFileMessageByURL interface.

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 NameParameter TypeRequiredDescription
filePathstringYesAbsolute file path, if none, empty string is fine
fileNamestringYesFile name
uuidstringYesUnique file ID
sourceUrlstringYesEmpty string is fine
fileSizenumberYesFile size
fileTypestringYesFile type
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();

IMSDK.createFileMessageByFile({
filePath: videoFile.path || '',
fileName: videoFile.name,
uuid: 'uuid',
sourceUrl: '',
fileSize: videoFile.size,
fileType: videoFile.type,
file: videoFile,
})
.then(({ data }) => {
// Call successful
})
.catch(({ errCode, errMsg }) => {
// Call failed
});