Skip to main content

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.

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 TypeMandatoryDescription
filePathstringYesThe absolute path of the file, use an empty string if not available
fileNamestringYesFile name
uuidstringYesUnique file ID
sourceUrlstringYesJust use an empty string
fileSizenumberYesFile size
fileTypestringYesFile type
fileFileYesFile object

Return Result

Parameter NameParameter TypeDescription
Promise.then()Promise<WsResponse<MessageItem>>Successful callback
Promise.catch()Promise<WsResponse>Failed callback

Code Example

import { getSDK } from 'open-im-sdk-wasm';
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
});