Create a file message from a local file
Create a pending file attachment message from an accessible local filesystem path.
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
| Parameter | Type | Required | Description |
|---|---|---|---|
filePath | string | Yes | Absolute POSIX file path or unifile:// URI accessible to the native runtime. |
fileName | string | Yes | Display 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) returnEnsure 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.
Was this page helpful?