Browse SDKs · uni-app / uni-app x
Platform
SDKsuni-app / uni-app x

Create a file message from a local file

Create a pending file attachment message from an accessible local filesystem path.

Copy

Invoke createFileMessageFromFullPath() to construct a pending file attachment message from a local file path. Supply the local filesystem path in filePath, and provide the file name and extension in fileName.

Parameters

ParameterTypeRequiredDescription
filePathstringYesAbsolute POSIX file path or unifile:// URI accessible to the native runtime.
fileNamestringYesDisplay file name presented to recipients (for example, 'project-plan.pdf').

Code example

import {
  createFileMessageFromFullPath,
} from '@/uni_modules/unix-openim-sdk'

const message = await createFileMessageFromFullPath({
  filePath: `${uni.env.USER_DATA_PATH}/project-plan.pdf`,
  fileName: 'project-plan.pdf',
})
if (message == null) return

Ensure fileName includes the appropriate extension for proper file association on recipient devices. If obtaining files via system pickers, copy them into uni.env.USER_DATA_PATH if transmission might occur asynchronously.

Return value

The Promise resolves with an OpenIMMessageItem | null object.

State changes after the call

Pass the constructed message item to Send a message. The SDK automatically handles binary upload and delivery, emitting upload progress events via onSendMessageProgress. Track items in your UI using clientMsgID.