浏览 SDKs · WASM
SDKsWASM

使用 URL 创建文件消息

使用 WASM SDK 从已上传 URL 创建文件消息。

复制

createFileMessageByURL() 使用已经上传的文件信息创建消息。

参数说明

参数类型是否必填说明
filePathstring文件的本地名称或业务路径;只有远端资源时传空字符串。
fileNamestring对外展示的文件名。
uuidstring文件资源的唯一标识。
sourceUrlstring已上传文件的可访问地址。
fileSizenumber文件大小,单位为字节。
fileTypestring文件 MIME 类型。
const { data: message } = await openimsdk.createFileMessageByURL({
  filePath: '',
  fileName: 'report.pdf',
  uuid: crypto.randomUUID(),
  sourceUrl: uploaded.url,
  fileSize: uploaded.size,
  fileType: 'application/pdf',
});

文件名、大小、类型和 URL 必须来自真实上传结果;只有远端资源时 filePath 传空字符串。Promise 成功只创建待发送对象。由于资源已上传,发送时使用 sendMessageNotOss()