Browse SDKs · WASM
SDKsWASM

Create a file message from a URL

Create a file message from an uploaded resource URL with the WASM SDK.

Copy

createFileMessageByURL() creates a message from information for a file that has already been uploaded.

Parameters

ParameterTypeRequiredDescription
filePathstringYesLocal filename or application-defined path of the file. Pass an empty string when only a remote resource is available.
fileNamestringYesFilename displayed to users.
uuidstringYesUnique identifier for the file resource.
sourceUrlstringYesAccessible URL of the uploaded file.
fileSizenumberYesFile size in bytes.
fileTypestringNoFile MIME type.
const { data: message } = await openimsdk.createFileMessageByURL({
  filePath: '',
  fileName: 'report.pdf',
  uuid: crypto.randomUUID(),
  sourceUrl: uploaded.url,
  fileSize: uploaded.size,
  fileType: 'application/pdf',
});

The filename, size, type, and URL must come from the actual upload result. Pass an empty string for filePath when only a remote resource is available. When the Promise resolves, it has created only a pending message object. Because the resource has already been uploaded, send it with sendMessageNotOss().