Browse SDKs · Flutter
Platform
SDKsFlutter

Create a file message

Create a file message from a platform path with the OpenIM Flutter SDK.

Copy

Construct a file message object from a local filesystem file path:

Parameters

ParameterTypeRequiredDescription
filePathStringYesLocal filesystem path to the file on the current device.
fileNameStringYesDisplay name of the file shown to recipients (include the file extension, such as document.pdf).

Code example

final message = await OpenIM.iMManager.messageManager.createFileMessage(
  filePath: filePath,
  fileName: fileName,
);

The specified path must be an accessible file with read permissions on the current device.

Return value

Returns a Future resolving to a file Message object ready for transmission. Its file properties are stored in fileElem.

State changes after the call

Creating a message only constructs the local message data structure in memory; it does not perform network transmission, does not upload files, and does not trigger new-message event callbacks. Once constructed, pass the returned Message instance to Send a message, which handles file upload and message delivery. To create a file message from an absolute filesystem path, see Create a file message from full path; if the file is already hosted on object storage, see Create a file message by URL.