Send files in chat
Users can transfer files in chat during a session. Send goes through the ZoomVideoSDKSession (for everyone) or a specific ZoomVideoSDKUser; receive happens through the onReceiveFileStatus callback, where you choose where to save the incoming file.
Zoom deletes files sent via in-session chat when the session ends.
Prerequisites
Enable send files via in-session chat in your Video SDK account portal settings and configure:
- 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.
Then check that the feature is actually available for this session.
val session = ZoomVideoSDK.getInstance().session
if (session.isFileTransferEnable) {
// Allowed file types (comma-separated): session.transferFileTypeWhiteList
// Max file size in bytes: session.maxTransferFileSize
}
ZoomVideoSDKSession session = ZoomVideoSDK.getInstance().getSession();
if (session.isFileTransferEnable()) {
// Allowed file types (comma-separated): session.getTransferFileTypeWhiteList()
// Max file size in bytes: session.getMaxTransferFileSize()
}
Send a file to everyone
transferFile on the session returns an int. 0 (ZoomVideoSDKErrors.Errors_Success) means the transfer is starting; any other value is an error code from ZoomVideoSDKErrors.
val result = ZoomVideoSDK.getInstance().session.transferFile("filePath")
if (result != ZoomVideoSDKErrors.Errors_Success) {
// Surface the error to the user.
}
int result = ZoomVideoSDK.getInstance().getSession().transferFile("filePath");
if (result != ZoomVideoSDKErrors.Errors_Success) {
// Surface the error to the user.
}
Send a file to a specific user
Call transferFile on a ZoomVideoSDKUser to send to that user only.
val userToReceiveFile: ZoomVideoSDKUser = /* ... */
val result = userToReceiveFile.transferFile("filePath")
if (result != ZoomVideoSDKErrors.Errors_Success) {
// Surface the error to the user.
}
ZoomVideoSDKUser userToReceiveFile = /* ... */;
int result = userToReceiveFile.transferFile("filePath");
if (result != ZoomVideoSDKErrors.Errors_Success) {
// Surface the error to the user.
}
Track send progress
After a transferFile call succeeds, the SDK reports progress through onSendFileStatus on your ZoomVideoSDKDelegate. Use the ZoomVideoSDKSendFile object passed to the callback to read the file name, current progress, and to call cancelSend() if the user backs out.
override fun onSendFileStatus(
file: ZoomVideoSDKSendFile?,
status: ZoomVideoSDKFileTransferStatus?
) {
if (file == null || status == null) return
when (status) {
ZoomVideoSDKFileTransferStatus.FileTransferState_Transfering -> {
// Update your progress UI from file.getRatio() (0-100).
}
ZoomVideoSDKFileTransferStatus.FileTransferState_TransferDone -> {
// Mark the upload complete in your UI.
}
ZoomVideoSDKFileTransferStatus.FileTransferState_TransferFailed -> {
// Surface the failure.
}
else -> {}
}
}
@Override
public void onSendFileStatus(
ZoomVideoSDKSendFile file,
ZoomVideoSDKFileTransferStatus status
) {
if (file == null || status == null) return;
switch (status) {
case FileTransferState_Transfering:
// Update your progress UI from file.getRatio() (0-100).
break;
case FileTransferState_TransferDone:
// Mark the upload complete in your UI.
break;
case FileTransferState_TransferFailed:
// Surface the failure.
break;
default:
break;
}
}
To cancel an in-progress upload, call cancelSend() on the ZoomVideoSDKSendFile instance while the status is FileTransferState_Transfering.
if (status == ZoomVideoSDKFileTransferStatus.FileTransferState_Transfering) {
file.cancelSend()
}
if (status == ZoomVideoSDKFileTransferStatus.FileTransferState_Transfering) {
file.cancelSend();
}
Receive a file
Incoming files arrive through onReceiveFileStatus. The first time the callback fires for a given file, status is FileTransferState_ReadyToTransfer. That's your cue to ask the user whether to accept the file, then call startReceive(path) with a destination path to begin the download.
override fun onReceiveFileStatus(
file: ZoomVideoSDKReceiveFile?,
status: ZoomVideoSDKFileTransferStatus?
) {
if (file == null || status == null) return
when (status) {
ZoomVideoSDKFileTransferStatus.FileTransferState_ReadyToTransfer -> {
// Ask the user whether to accept the file, then:
file.startReceive("destinationPath")
}
ZoomVideoSDKFileTransferStatus.FileTransferState_Transfering -> {
// Update your progress UI.
}
ZoomVideoSDKFileTransferStatus.FileTransferState_TransferDone -> {
// The file has been written to the destination path you passed earlier.
}
ZoomVideoSDKFileTransferStatus.FileTransferState_TransferFailed -> {
// Surface the failure to the user.
}
else -> {}
}
}
@Override
public void onReceiveFileStatus(
ZoomVideoSDKReceiveFile file,
ZoomVideoSDKFileTransferStatus status
) {
if (file == null || status == null) return;
switch (status) {
case FileTransferState_ReadyToTransfer:
// Ask the user whether to accept the file, then:
file.startReceive("destinationPath");
break;
case FileTransferState_Transfering:
// Update your progress UI.
break;
case FileTransferState_TransferDone:
// The file has been written to the destination path you passed earlier.
break;
case FileTransferState_TransferFailed:
// Surface the failure to the user.
break;
default:
break;
}
}
To cancel an in-progress download, call cancelReceive() on the ZoomVideoSDKReceiveFile while the status is FileTransferState_Transfering.
if (status == ZoomVideoSDKFileTransferStatus.FileTransferState_Transfering) {
file.cancelReceive()
}
if (status == ZoomVideoSDKFileTransferStatus.FileTransferState_Transfering) {
file.cancelReceive();
}
File transfer status values
ZoomVideoSDKFileTransferStatus is the same enum for both directions.
| Status | Meaning | What to do |
|---|---|---|
FileTransferState_None | Initial / no-op state. | No action. |
FileTransferState_ReadyToTransfer | An incoming file is ready to begin downloading. | On the receive side, prompt the user and call startReceive(path). Does not fire on the send side. |
FileTransferState_Transfering | The transfer is in progress. | Update progress UI from file.getRatio() (0–100). Cancel with cancelSend() / cancelReceive() while in this state. |
FileTransferState_TransferFailed | The transfer failed. | Surface the failure to the user; the file object is no longer usable. |
FileTransferState_TransferDone | The transfer completed successfully. | Mark the upload/download complete in your UI. |