跳到主要内容

createVideoMessageByFile

功能介绍

说明

根据文件对象创建视频消息。

注意

仅 web 端支持,且最好不要用于大文件上传,大于1G的文件上传,建议使用createVideoMessageByURL接口

函数原型

IMSDK.createVideoMessageByFile({
videoPath: string;
duration: number;
videoType: string;
snapshotPath: string;
videoUUID: string;
videoUrl: string;
videoSize: number;
snapshotUUID: string;
snapshotSize: number;
snapshotUrl: string;
snapshotWidth: number;
snapshotHeight: number;
snapShotType: string;
videoFile: File;
snapshotFile: File;
}, operationID?: string): Promise<WsResponse<MessageItem>>

输入参数

参数名称参数类型是否必填描述
videoPathstring文件绝对路径,如果没有传空字符即可
durationnumber视频时长
videoTypestring文件类型,一般为后缀名
snapshotPathstring视频封面图路径,传空字符串即可
videoUUIDstring视频文件唯一 ID
videoUrlstring视频下载地址,自行上传并通过sendMessageNotOss 发送时,需要传入远程 url,否则为空字符串
videoSizenumber文件大小
snapshotUUIDstring视频封面唯一 ID
snapshotSizenumber视频封面图大小
snapshotUrlstring视频封面图下载地址,自行上传并通过sendMessageNotOss 发送时,需要传入远程 url,否则为空字符串
snapshotWidthnumber视频缩略图宽度
snapshotHeightnumber视频缩略图高度
snapShotTypestring视频缩略图类型,一般为后缀名
videoFileFile视频文件对象
snapshotFileFile视频封面图文件对象

返回结果

参数名称参数类型描述
Promise.then()Promise<WsResponse<MessageItem>>调用成功回调
Promise.catch()Promise<WsResponse>调用失败回调

代码示例

import { getSDK } from 'open-im-sdk-wasm';
const IMSDK = getSDK();

// use in electron with ffi
// import { getWithRenderProcess } from '@openim/electron-client-sdk/lib/render';
// const { instance: IMSDK } = getWithRenderProcess();

// use in mini program
// import { OpenIMSDK } from 'open-im-sdk';
// const IMSDK = new OpenIMSDK();

IMSDK.createVideoMessageByFile({
videoPath: videoFile.path,
duration: 6,
videoType: videoFile.type,
snapshotPath: snapshotFile.path,
videoUUID: '',
videoUrl: '',
videoSize: videoFile.size,
snapshotUUID: '',
snapshotSize: snapshotFile.size,
snapshotUrl: '',
snapshotWidth: 1024,
snapshotHeight: 1024,
snapShotType: snapshotFile.type,
videoFile,
snapshotFile,
})
.then(({ data }) => {
// 调用成功
})
.catch(({ errCode, errMsg }) => {
// 调用失败
});