Availability: Android SDK v1.5.3+

The following APIs allow users in an RTC session to send and receive file(s) with each other. Using these APIs, you can initiate a file transfer, cancel a file transfer, be notified of the availability of a file for download, and receive/download a shared file.

Table of Contents

Upload File to share

The EnxRoom.sendFiles() method is used to initiate a file transfer to EnableX Server.

Class: EnxRoom

Observer: public void setFileShareObserver(EnxFileShareObserver-Object)

Method: public void sendFiles(FrameLayout view, boolean isBroadcast, List clientIdList)

Parameters:

  • view– FrameLayout view where UI is shown to choose files to upload.
  • isBroadcast – Boolean. Set it to true to share file(s) with all the participants in the Session and false to share file(s) with the intended user(s).
  • clientIdList – List of Client IDs intended to receive the file(s). This parameter is not applicable if isBroadcast parameter is set to true.

Callbacks at Sender’s End:

  • onInitFileUpload – Notification to the sender when the file upload process is initiated.
  • onFileUploaded – Notification to the sender when the file has been uploaded.
  • onFileUploadFailed – Notification to the sender when the file upload process fails.

Callbacks at Receiver’s End:

  • onFileUploadStarted – Notification to the intended receiver when a file is being uploaded.
  • onFileAvailable – Notification to the intended receiver when a file is ready to download.
room.sendFiles(FrameLayoutView, true, NULL); 

// To intended receiver - A new file upload started 
public void onFileUploadStarted(JSONObject jsonObject) {
       // Handle JSON Object with file information
}

// To intended receiver - A file is available for download 
public void onFileAvailable(JSONObject jsonObject) {
	// Handle JSON Object with file information
}

// To sender - File upload process started
public void onInitFileUpload(JSONObject jsonObject) {
	// Handle JSON Object with file information
}

// To sender - File upload is complete
public void onFileUploaded(JSONObject jsonObject) {
	// Handle JSON Object with file information
}

// To sender - File upload has failed
public void onFileUploadFailed(JSONObject jsonObject) {
	// Handle upload error
}

Download shared File

The process of downloading shared file(s) comprises two steps:

  • Know file(s) available for download.
  • Initiate download on the available file(s).

Know files available for download

The EnxRoom.getAvailableFiles() method returns a JSON Object with all the files available for download.

Class: EnxRoom

Method: public JSONObject getAvailableFiles()

let myFiles = room.availableFiles;

// myFile contains array of File Information
[
	{
		name: "DP1.pdf",  
		size: 191002,
		index: 0 // ID or File Reference
	} 
]

Callback onFileAvailable: The intended receiver is notified when a file is available for download.

// To intended receiver - A file is available for download 
public void onFileAvailable(JSONObject jsonObject) {
	// Handle JSON Object with file information
}

Initiate File Download

The EnxRoom.downloadFile() method is used to initiate the file download using the file information received above.

Class: EnxRoom

Method: public void downloadFile(JSONObject fileInfo, boolean isAutoSave)

Parameters:

  • fileInfo– File JSON Object available for download.
  • isAutoSave – Boolean. Set it to true to save the file automatically in which case you receive the saved file’s path. When set to false, you receive Base64 encoded RAW data to handle the file saving process manually.

Callbacks at Receiver’s End:

  • onFileDownloaded – Notification sent when the file has been downloaded with or without auto-saving.
  • onFileDownloadFailed – Notification sent when download fails.
room.downloadFile(JSONObject, true); 

// To receiver - File has been downloaded
public void onFileDownloaded(JSONObject jsonObject) {
       // Handle JSON Object with file information
}

// To receiver - File download has failed
public void onFileDownloadFailed(JSONObject jsonObject) {
	// Handle download error
}

Cancel File Upload

The EnxRoom.cancelUpload() method allows you to cancel an ongoing file upload job initiated by you.

Class: EnxRoom

Method: public void cancelUpload(int upJobId)

Parameter:

upJobId – Numeric. The Id of the file upload job.

enxRoom.cancelUpload(jobId);

The EnxRoom.cancelAllUploads() method allows you to cancel all ongoing file uploads initiated by you.

Method: public void cancelAllUploads() – No Parameter required.

enxRoom.cancelAllUploads();

Callback:

onFileUploadCancelled – Acknowledgment to the user when the file upload is canceled.

public void onFileUploadCancelled(JSONObject jsonObject)

Error Codes / Exceptions:

CodeDescription
5089Storage Access denied.
5090Failed to save file.
5091File-Sharing not available in this context.
5092Too many files to upload. Max 1 file allowed per request.
1185File size exceeds the max allowed size.
1182Failed to upload file.
5098Unable to cancel file upload after file upload complete.
5099Failed to cancel upload as invalid Upload ID passed as a parameter.
5100Failed to upload a possibly corrupt file.
5102Cancel upload not available without Web View. Non-Contextual Method Call.

Cancel File Download

The EnxRoom.cancelDownload() allows you to cancel the ongoing file download job taking place at your endpoint.

Class: EnxRoom

Method: public void cancelDownload(int upJobId)

Parameter:

upJobId – Numeric. The Id of the file download job.

enxRoom.cancelDownload(jobID);

The EnxRoom.cancelAllDownloads() method allows you to cancel all ongoing file downloads taking place at your endpoint.

Method: public void cancelAllDownloads() – No Parameter required.

enxRoom.cancelAllDownloads();

Callback:

onFileDownloadCancelled – Acknowledgment to the user when the file download is canceled.

public void onFileDownloadCancelled(JSONObject jsonObject);

Error Codes / Exceptions:

CodeDescription
5089Storage Access denied.
5090Failed to save file.
1183Failed to download file.
1181File Download not available. Non-contextual Method Call.
5101File already downloaded.