Skip to main content

createSoundMessageByFile

Description

info

Create an audio message based on a file object.

Note

Only supported on the Web side.

Function Prototype

IMSDK.createSoundMessageByFile({
uuid: string;
soundPath: string;
sourceUrl: string;
dataSize: number;
duration: number;
soundType: string;
file: File;
}, operationID?: string): Promise<WsResponse<MessageItem>>

Input Parameters

Parameter NameParameter TypeRequiredDescription
soundPathstringYesAbsolute file path, if none, empty string is fine
durationnumberYesRecording duration
uuidstringYesUnique file ID
sourceUrlstringYesRecording download address. When uploading the file yourself and sending via sendMessageNotOss, this needs to be the remote URL; otherwise, it should be an empty string
dataSizestringYesFile size
soundTypestringYesFile type, usually the extension
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.createSoundMessageByFile({
soundPath: soundFile.path,
duration: 6,
uuid: 'uuid',
sourceUrl: '',
dataSize: soundFile.size,
soundType: soundFile.type,
file: soundFile,
})
.then(({ data }) => {
// Call successful
})
.catch(({ errCode, errMsg }) => {
// Call failed
});