Browse SDKs · Electron
SDKsElectron

Create media messages from full paths

Use the Electron FFI *FromFullPath APIs to create image, video, audio, and file messages from absolute local paths.

Copy

Electron FFI provides a set of APIs for creating media messages from complete local file paths. They are intended for desktop applications that already have an absolute disk path, such as one returned by a system file picker. Browser applications and Electron applications using WASM should use the corresponding *ByFile or *ByURL methods. For images, see Create an image message from a file and Create an image message from a URL. For independent file uploads, see Upload a file.

After creating a MessageItem, send it with sendMessage() just like any message that uses the shared message model. See Send a message for sending parameters and events.

Supported methods

MethodPurpose
createImageMessageFromFullPath(imagePath)Create an image message from an absolute local image path.
createSoundMessageFromFullPath(params)Create an audio message from an absolute local audio path.
createVideoMessageFromFullPath(params)Create a video message from absolute video and snapshot paths.
createFileMessageFromFullPath(params)Create a regular file message from an absolute local path.

These methods create message objects only. They do not send a message automatically or trigger a new-message event.

Image messages

createImageMessageFromFullPath() accepts the image's absolute file path directly.

const { data: message } = await openimsdk.createImageMessageFromFullPath(
  '/absolute/path/to/photo.jpg',
);

await openimsdk.sendMessage({
  recvID,
  groupID: '',
  message,
});

Audio messages

Parameters

ParameterTypeRequiredDescription
soundPathstringYesAbsolute path to the audio file.
durationnumberYesAudio duration. Pass an integer rather than a decimal value.
const { data: message } = await openimsdk.createSoundMessageFromFullPath({
  soundPath: '/absolute/path/to/voice.m4a',
  duration: 3200,
});

Video messages

Parameters

ParameterTypeRequiredDescription
videoPathstringYesAbsolute path to the video file.
videoTypestringYesVideo type, such as mp4.
durationnumberYesVideo duration. Pass an integer rather than a decimal value.
snapshotPathstringYesAbsolute path to the video cover snapshot.
const { data: message } = await openimsdk.createVideoMessageFromFullPath({
  videoPath: '/absolute/path/to/clip.mp4',
  videoType: 'mp4',
  duration: 12000,
  snapshotPath: '/absolute/path/to/cover.jpg',
});

File messages

Parameters

ParameterTypeRequiredDescription
filePathstringYesAbsolute path to the file.
fileNamestringYesFile name displayed to conversation members.
const { data: message } = await openimsdk.createFileMessageFromFullPath({
  filePath: '/absolute/path/to/report.pdf',
  fileName: 'report.pdf',
});

Results

When any of the four *FromFullPath Promises succeeds, its data is a MessageItem ready to send. A subsequent successful sendMessage() Promise means only that the send request completed. The recipient confirms delivery through its new-message event.