SDKsWASM
使用 URL 创建文件消息
使用 WASM SDK 从已上传 URL 创建文件消息。
当普通文件已预先通过业务文件服务器或云存储上传并取得可访问 URL 时,可调用 createFileMessageByURL() 构建待发送文件消息:
参数说明
| 参数 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
filePath | string | 是 | 文件的本地名称或业务路径;只有远端资源时传空字符串。 |
fileName | string | 是 | 对外展示的文件名。 |
uuid | string | 是 | 文件资源的唯一标识。 |
sourceUrl | string | 是 | 已上传文件的可访问地址。 |
fileSize | number | 是 | 文件大小,单位为字节。 |
fileType | string | 否 | 文件 MIME 类型。 |
const { data: message } = await openimsdk.createFileMessageByURL({
filePath: '',
fileName: 'report.pdf',
uuid: crypto.randomUUID(),
sourceUrl: uploaded.url,
fileSize: uploaded.size,
fileType: 'application/pdf',
});文件名、大小、MIME 类型和 URL 必须与真实上传文件相对应;当仅有远端资源时,filePath 传空字符串即可。接口调用成功后返回待发送的 MessageItem 对象,后续需使用 发送已上传的媒体消息(sendMessageNotOss)投递该消息。
这个页面有帮助吗?