Send files in chat

View as Markdown

Users can transfer files in chat during the session.

Enable send files via in-session chat in your Video SDK account portal settings and configure the following settings.

  • Only allow specified file types - Select to allow only specific file types and enter the file extensions in the text box, separated by commas.
  • Maximum file size - Select to limit the file size to 2048 MB.

Check if the file transfer feature is enabled.

let ret = ZMVideoSDK.shared().getSessionInfo().isFileTransferEnabled()

Get the list of allowed file types that you can transfer.

let ret = ZMVideoSDK.shared().getSessionInfo().getTransferFileTypeWhiteList()

Get the maximum file size to transfer.

let ret = ZMVideoSDK.shared().getSessionInfo().getMaxTransferFileSize()

Send files to all users in the current session.

let ret = ZMVideoSDK.shared().getSessionInfo().transferFile(filePath: String)

Send files to a certain user in the session.

// Locate the user that you would like to send the file to.
let receiver: ZMVideoSDKUser

// Send file directly.
let ret = receiver.transferFile(filePath: String)

Cancel sending files.

// getCurrentSendFileObj is a user-defined method, to retrieve the sending file.
let sendFile: ZMVideoSDKSendFile = getCurrentSendFileObj()
let ret = sendFile.cancelSend()

Start receiving files.

// getCurrentReceiveFileObj is a user-defined method, to retrieve the receiving file.
let receiveFile: ZMVideoSDKReceiveFile = getCurrentReceiveFileObj()

let fileDomain = FileManager.default.urls(for: .downloadsDirectory, in: .userDomainMask).map(\.path).last
let filePath = "<File path to receive>"
let downloadFilePath = "\(fileDomain)/\(filePath.count > 0 ? filePath : receiveFile.fileName)"

if (receiveFile) {
  let ret = receiveFile.startReceive(downloadFilePath)
  }

Cancel receiving files.

// getCurrentReceiveFileObj is a user-defined method, to retrieve the receiving file.
let receiveFile: ZMVideoSDKReceiveFile = getCurrentReceiveFileObj()

if (receiveFile) {
  let ret = receiveFile.cancelReceive()
  }

File transfer callbacks

Be sure that you have set up a delegate for callback events to receive file transfer callbacks.

Get notified when you transfer a file.

func onSendFile(_ sendFile: ZMVideoSDKSendFile!, status: ZMVideoSDKFileTransferStatus) {
  // Get the transfer status of the file and the file content here.
  }

Get notified when you receive a file from other users.

func onReceiveFile(_ receiveFile: ZMVideoSDKReceiveFile!, status: ZMVideoSDKFileTransferStatus) {
  // Get the transfer status of the file and the file content here.
  }