SDKsWASM
Create a video message from files
Create a video message from browser video and thumbnail files with the WASM SDK.
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
| Parameter | Type | Required | Description |
|---|---|---|---|
videoFile | File | Yes | Original video file from the browser. |
snapshotFile | File | Yes | Video thumbnail file from the browser. |
videoPath | string | Yes | Local filename or application-defined path of the video file. |
duration | number | Yes | Video duration in seconds. |
videoType | string | Yes | Video MIME type. |
videoUUID | string | Yes | Unique identifier for the video resource. |
videoUrl | string | Yes | Video URL. Pass an empty string when creating from a file. |
videoSize | number | Yes | Video size in bytes. |
snapshotPath | string | Yes | Local filename or application-defined path of the thumbnail file. |
snapshotUUID | string | Yes | Unique identifier for the thumbnail resource. |
snapshotSize | number | Yes | Thumbnail size in bytes. |
snapshotUrl | string | Yes | Thumbnail URL. Pass an empty string when creating from a file. |
snapshotWidth | number | Yes | Thumbnail width in pixels. |
snapshotHeight | number | Yes | Thumbnail height in pixels. |
snapShotType | string | No | Thumbnail 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.
Was this page helpful?