Browse SDKs · WASM
SDKsWASM

Create a file message from a file

Create a file message from a browser File with the WASM SDK.

Copy

createFileMessageByFile() creates a message from a browser file and its metadata.

Parameters

ParameterTypeRequiredDescription
fileFileYesOriginal file from the browser.
filePathstringYesLocal filename or application-defined path of the file.
fileNamestringYesFilename displayed to users.
uuidstringYesUnique identifier for the file resource.
sourceUrlstringYesFile URL. Pass an empty string when creating from a file; the SDK uploads the file during sending.
fileSizenumberYesFile size in bytes.
fileTypestringNoFile 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.