EnableX File Share API allows users of a RTC session to send and receive file(s) to/from each other. Using the available APIs, you can initiate file transfer to share, cancel a file transfer, get notified on a shared file and receive/download shared file.

Table of Contents

Upload File to Share

The file sharing process starts with a user initiating a file transfer to EnableX Server. To initiate a file transfer use sendFiles() method.

Method: static Future<void> sendFiles(bool isBroadCast, List<dynamic> recipientIDs)

Parameters:

  • @param bool isBroadcast – Boolean. This is to share file among all participants in the Session. If you need to target the file share to specific user, then set it to false.
  • @param List recipientIDs– List of Client IDs. This is to share the file among specified Clients only. If broadcast is set to true, recipientIDs is ignored.

Callbacks at Sender End:

  • onInitFileUpload – To notify sender that file upload process is initiated
  • OnFileUploaded – To notify sender that file has been uploaded
  • OnFileUploadFailed – To notify sender that file upload process has failed

Callbacks at Receiver End:

  • OnFileUploadStarted – To notify intended receiver that a file is being uploaded
  • OnFileAvailable – To notify intended received that a file is ready to download
EnxRtc.sendFile(true,[]);	// Send Files

EnxRtc.onInitFileUpload = (Map<dynamic,dynamic> map) {
	// File upload started
};

EnxRtc.onFileUploaded = (Map<dynamic,dynamic> map) {
	// File is uploaded
};

EnxRtc.onFileUploadFailed = (Map<dynamic,dynamic> map) {
	// File upload failed
};

EnxRtc.onFileUploadStarted = (Map<dynamic,dynamic> map) {
	// File upload started... to recipient
};

EnxRtc.onFileAvailable = (Map<dynamic,dynamic> map) {
	// Files available for download... to recipient
};

Error Codes: Upload process may encounter error.

Error CodeError Description
5089Storage Access denied
5091 File Sharing not available in this context
1185Too large file. Max allowed Size: NNNN
1182Failed to upload file

Cancel a File Upload

Sender of a file may like to cancel an ongoing file upload. To do so use cancelUpload() method.

Method: static Future<void> cancelUpload(int jobId)

Parameters: @param int jobId – Job ID which is to be cancelled.

Event Listeners: onFileUploadCancelled – It notifies when the file upload cancelled successfully

EnxRtc.cancelFileUpload(jobId);		// Cancel File uploading

EnxRtc.onFileUploadCancelled = (Map<dynamic,dynamic> map) {
	// Upload has been cancelled
};

Cancel all Files Upload

Sender of multiple files may like to cancel an ongoing files upload. To do so use cancelAllUploads() method.

Method: static Future<void> cancelAllUploads()

Parameters: @param int jobId – Job ID which is to be cancelled.

Event Listeners: onFileUploadCancelled – It notifies when the file upload cancelled successfully

EnxRtc.cancelAllUploads();	// Cancel Files uploading

EnxRtc.onFileUploadCancelled = (Map<dynamic,dynamic> map) {
	// Upload has been cancelled
};

Download shared File

Intended Recipients needs to download each file shared with them individually. Therefore, recipient needs to know information on the available files to download to initiate a download process.

Know files to download

Room Lookup: To know what all files are available for download, you may call EnxRoom.getAvailableFiles() method. It returns list of File data.

Method: static Future<List<dynamic> getAvailableFiles()

List<dynamic> list= EnxRtc.getAvailableFiles();

When New File is availble: A receive end point is notified as and when a file is made available for download using Event Listener onFileAvailable

Initiate File Download

As you know about the file(s) to download, you need to initiate download individually using downloadFile() method.

Method: static Future<void> downloadFile(Map<String,dynamic> file, bool autoSave)

Parameters:

  • @param Map fileInfo– Map of file to be downloaded.
  • @param bool autosave– Whether to save the file automatically. If not to be save automatically, you would receive Base64 encoded RAW data to handle file saving processes manually. If auto-saving is on, you would receive saved file path.

Callbacks at Receiver End:

  • onFileDownloaded – To notify file has been downloaded with either Base64 Raw data to be saved (When auto-saving is false) or saved file path.
  • OnFileDownloadFailed – To notify download failure
EnxRtc.downloadFile(fileInfo,true);	// Download a File

EnxRtc.onFileDownloaded = (Map<dynamic,dynamic> map) {
	// File has been downloaded
};

EnxRtc.onFileDownloadFailed = (Map<dynamic,dynamic> map) {
	// File Download has failed 
};

Error Codes: Download process may encounter error.

Error CodeError Description
5089Storage Access denied
5090Failed to save file
1183Failed to download file
1181File Download not available in this context

Cancel downloading a File

Receiver of a file may like to cancel an ongoing download of a file by using cancelDownload() method.

Method: static Future<void> cancelDownload(int jobId)

Parameters: @param int jobId – Job ID which is to be cancelled.

Event Listeners: onFileDownloadCancelled – It notifies when the file download is cancelled.

EnxRtc.cancelFileDownload(jobId);	// Cancel a download job

EnxRtc.onFileDownloadCancelled=(Map<dynamic,dynamic> map) {
	// File download has been cancelled
};

Cancel downloading all Files

Receiver of files may like to cancel ongoing download of all files by using cancelAllDownloads() method.

Method: static Future<void> cancelAllDownloads()

Event Listeners: onFileDownloadCancelled – It notifies when the file download is cancelled.

EnxRtc.cancelAllDownloads();	// Cancel  download job

EnxRtc.onFileDownloadCancelled=(Map<dynamic,dynamic> map) {
	// File download has been cancelled
};