Browse SDKs · HarmonyOS
Platform
SDKsHarmonyOSEnterprise

Create file message from local file

Create a file message from an accessible local filesystem path.

Copy

Creates a file message object using a local filesystem path accessible to the application.

Code example

import sdk, { CreateFileMessageReq, CreateFileMessageResp } from '@openimsdk/imsdk';

const request: CreateFileMessageReq = {
  fileSourcePath: filePath,
  fileName: 'ProjectPlan.pdf',
};
const response: CreateFileMessageResp = await sdk.createFileMessage(request);
const message = response.message;

Parameters

ParameterTypeRequiredDescription
fileSourcePathstringYesLocal filesystem path readable by the native SDK.
fileNamestringYesFile display name shown to receiving users, including extension.

Return value

Returns a Promise resolving to CreateFileMessageResp:

PropertyTypeDescription
messageIMMessageLocally instantiated file message object.

State changes after the call

fileSourcePath must be accessible to the native SDK layer. fileName is displayed and saved by receiving clients and should preserve appropriate file extensions without substituting for real file content validation. Resolving the Promise creates the message object locally; calling Send message subsequently uploads the file through the SDK and sends the message.