Browse SDKs · WASM
SDKsWASM

Create a video message from files

Create a video message from browser video and thumbnail files with the WASM SDK.

Copy

createVideoMessageByFile() creates a message from a browser video file, its video thumbnail, and their metadata. The SDK field names retain snapshot, while this page uses “video thumbnail” for the user-facing concept.

Parameters

ParameterTypeRequiredDescription
videoFileFileYesOriginal video file from the browser.
snapshotFileFileYesVideo thumbnail file from the browser.
videoPathstringYesLocal filename or application-defined path of the video file.
durationnumberYesVideo duration in seconds.
videoTypestringYesVideo MIME type.
videoUUIDstringYesUnique identifier for the video resource.
videoUrlstringYesVideo URL. Pass an empty string when creating from a file.
videoSizenumberYesVideo size in bytes.
snapshotPathstringYesLocal filename or application-defined path of the thumbnail file.
snapshotUUIDstringYesUnique identifier for the thumbnail resource.
snapshotSizenumberYesThumbnail size in bytes.
snapshotUrlstringYesThumbnail URL. Pass an empty string when creating from a file.
snapshotWidthnumberYesThumbnail width in pixels.
snapshotHeightnumberYesThumbnail height in pixels.
snapShotTypestringNoThumbnail MIME type.
const { data: message } = await openimsdk.createVideoMessageByFile({
  videoFile,
  snapshotFile,
  videoPath: videoFile.name,
  duration,
  videoType: videoFile.type,
  videoUUID: crypto.randomUUID(),
  videoUrl: '',
  videoSize: videoFile.size,
  snapshotPath: snapshotFile.name,
  snapshotUUID: crypto.randomUUID(),
  snapshotSize: snapshotFile.size,
  snapshotUrl: '',
  snapshotWidth,
  snapshotHeight,
  snapShotType: snapshotFile.type,
});

If the browser reports the video duration in milliseconds, convert it to seconds before passing it. When the Promise resolves, it has created only a pending message object. Use sendMessage() afterward to upload and send it.