SDKsWASM
Create a file message from a file
Create a file message from a browser File with the WASM SDK.
createFileMessageByFile() creates a message from a browser file and its metadata.
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
file | File | Yes | Original file from the browser. |
filePath | string | Yes | Local filename or application-defined path of the file. |
fileName | string | Yes | Filename displayed to users. |
uuid | string | Yes | Unique identifier for the file resource. |
sourceUrl | string | Yes | File URL. Pass an empty string when creating from a file; the SDK uploads the file during sending. |
fileSize | number | Yes | File size in bytes. |
fileType | string | No | File MIME type. |
const { data: message } = await openimsdk.createFileMessageByFile({
file,
filePath: file.name,
fileName: file.name,
uuid: crypto.randomUUID(),
sourceUrl: '',
fileSize: file.size,
fileType: file.type,
});file is the browser file object; all other metadata must describe that same file. When the Promise resolves, it returns only a pending message object. Use sendMessage() afterward to enter the SDK's media upload and send flow.
Was this page helpful?