Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface IBaseSendFileOptions

Hierarchy

Index

Properties

antiSpamInfo?: TMsgAntiSpamInfo

反垃圾相关配置

如果通过 CloudStorageServiceInterface.uploadFile 上传过文件,则直接使用上传结果作为 attach即可。

example
// 先上传文件,再发送文件消息
const file = document.getElementById('file-input').files[0]

const uploadFileRes = await nim.cloudStorage.uploadFile({
type: 'audio'
file: file
})

nim.msg.sendAudioMsg({
scene: 'p2p',
to: 'test',
attach: uploadFileRes
})
body?: string

文本消息内容。

callbackExt?: string

第三方回调的扩展字段

ext?: string

扩展字段。消息发送后,消息体中的 ext 属性等于发送消息时设置的 ext属性值

file?: File

JS 的 File 对象。该属性和 fileInput, filePath仅需要填一个即可

该属性仅在使用 NIM_BROWSER_SDK.js 时可以使用

fileInput?: string | HTMLInputElement
deprecated

请使用 IBaseUploadFileOptions.file 属性

存储文件的 DOM 元素,与上面的 file 只要选填一个就可以了。

  • 该属性仅在使用 NIM_BROWSER_SDK.js 时可以使用
  • 如果传字符串,最后会以 document.getElementById('fileInput').files[0] 拿到 File 对象
  • 如果传的是 DOM 节点,最后以 fileInput.files[0] 拿到 File 对象
filePath?: string

临时文件路径

  • uni-app,小程序等特殊的 JS 运行环境专用(chooseImage 拿到的临时路径)
  • 仅当使用 NIM_UNIAPP_SDK.js, NIM_MINIAPP_SDK.js 时可以使用
example
// 微信小程序选择音频,并发送音频文件消息
wx.chooseMedia({
count: 1,
mediaType: ['vedio'],
success: (res) => {
let r = this.nim.msg.sendAudioMsg({
"scene": "p2p",
"to": "cs5",
"filePath": res.tempFiles[0].tempFilePath
})
r.then((res) => {
// 输出结果
console.log('sendAudioMsg 完成:', res)
}).catch((e) => {
console.error('sendAudioMsg 出错:', e)
})
}
})
idClient?: string

消息客户端唯一标识。只在于重发时可以指定

maxSize?: number

maxSize 限制文件大小。

只对浏览器生效。

uni-app,小程序等,由于sdk只能得到一个 filePath 临时路径,不能得到整个文件的信息。 所以请开发者自行在选择文件后进行判断,参考那些端的API如 wx.chooseImage,uni.chooseImage

nosScenes?: string

存储场景,不传默认实例化配置,默认为"im"

常见说明

  • 常用场景为根据资源类型设置存储场景,然后设置定时任务调用 清理文件 删除。
  • IM 默认的存储场景为: 'im'
  • Chatroom 默认的存储场景为: 'chatroom'
nosSurvivalTime?: number

存储有效时间,不传则默认实例化配置

不得小于一天,单位秒

pushInfo?: TMsgPushInfo

推送相关配置

replyMsg?: IMMessage

回复消息时,可以设置 replyMsg。设置回复消息后,后续可通过消息扩展接口查询消息的回复关系。请参考文档:消息扩展

example
// 回复消息
nim.msg.sendText({
scene: 'p2p',
to: 'test',
text: 'reply hello world',
replyMsg: msg,
done: (e, r) => console.log(e ? '发送消息失败' : '发送消息成功')
})

// 输入根消息节点,查询该消息所有的回复消息
const res = await nim.msgExtend.getThreadMsgs({
"scene": "p2p",
"threadMsgFromAccount": "zk1",
"threadMsgIdServer": rootMsg.idServer,
"threadMsgTime": rootMsg.time,
"threadMsgToAccount": "zk2",
"limit": 100,
"reverse": false
})
scene: "p2p" | "team" | "superTeam"

场景

  • 'p2p' (单人聊天)
  • 'team' (群聊)
  • 'superTeam' (超大群聊天)
setting?: TMsgSetting

消息的杂项设置

subType?: number

消息子类型,格式为大于0的整数,开发者可自定义

teamSpecializationInfo?: Pick<TMsgTeamSpecializationInfo, "needACK">

群组特化的杂项配置。

发送消息时,仅支持设置 needACK 属性

to: string

接收方, 对方帐号或者群id

Methods

  • 发送前的回调函数,用于发送前拿到这个消息对象

    • 此时这个消息对象还没有 idServer 和准确的 time,并且 status 也只是在 sending
    • 发送失败时,可以用该回调保存消息,然后调用 MsgServiceInterface.resendMsg 重发
    example
    try {
    let tempMsg
    await nim.msg.sendTextMsg({
    scene: 'p2p',
    to: 'test',
    body: 'message',
    onSendBefore: (msg) => {
    // 发送消息前,通过该回调临时存储消息
    tempMsg = msg
    }
    })
    } catch(err) {
    // 发送失败
    tempMsg.status = 'sendFailed'
    }

    // 如果发送失败,调用 resendMsg 重发消息
    nim.msg.resendMsg({
    msg: tempMsg
    })

    Parameters

    Returns void

  • onUploadStart(task: { abort: any }): void
  • 上传前回调事件。可以使用该回调参数的 abort 函数取消上传

    example
    // 取消上传
    const file = document.getElementById('file-input').files[0]

    nim.msg.sendImageMsg({
    scene: 'p2p',
    to: 'test',
    file: file,
    onUploadStart: (task) => {
    // 调用 abort 取消上传
    task.abort()
    }
    })

    Parameters

    • task: { abort: any }
      • [key: string]: any
      • abort:function
        • abort(): void
        • Returns void

    Returns void