Availability: iOS SDK v1.5.3+
Compatibility: iOS 13+
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
Method: -(void) shareFiles:(EnxFilePosition)position isBroadcast:(BOOL)isBroadcast clientIds:(NSArray *_Nullable)clientIds
Parameters:
position
– EnxFilePosition. Enumerated values: Top, Bottom, Center. Placement of File Selection UI.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).clientIds
– List of Client IDs intended to receive the file(s). This parameter is not applicable ifisBroadcast
parameter is set to true.
Delegate Methods at Sender End:
-room:didInitFileUpload:
– Notification to the sender when the file upload process is initiated.-room:didFileUploaded:
– Notification to the sender when the file has been uploaded.-room:didFileUploadFailed:
– Notification to the sender when the file upload process fails.
Delegate Methods at Receiver End:
-
-room:didFileUploadStarted:
– Notification to the intended receiver when a file is being uploaded. -
-room:didFileAvailable:
– Notification to the intended receiver when a file is ready to download.
[room shareFiles:Top isBroadcast:true clientIds:nil]; // To intended receiver - A new file upload started - (void)room:(EnxRoom *_Nonnull)room didFileUploadStarted:(NSArray *_Nullable)data { // data contains incoming file information } // To intended receiver - A file is available for download -(void)room:(EnxRoom *_Nonnull)room didFileAvailable:(NSArray *_Nullable)data { // data contains incoming file information } // To sender - File upload process started - (void)room:(EnxRoom *_Nonnull)room didInitFileUpload:(NSArray *_Nullable)data { // data contains file information } // To sender - File upload is complete - (void)room:(EnxRoom *_Nonnull)room didFileUploaded:(NSArray *_Nullable)data { // data contains file information } // To sender - File upload has failed - (void)room:(EnxRoom *_Nonnull)room didFileUploadFailed:(NSArray *_Nullable)data { // data contains error information }
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
Room Lookup: The EnxRoom.getAvailableFiles()
method returns a JSON Object with all the files available for download.
Class: EnxRoom
Method: -(NSArray*)getAvailableFiles
[room getAvailableFiles];
Delegate method -room:didFileAvailable:
The intended receiver is notified when a file is available for download.
// To intended receiver - A file is available for download -(void)room:(EnxRoom *_Nonnull)room didFileAvailable:(NSArray *_Nullable)data { // data contains incoming 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: -(void)downloadFile:(NSDictionary *_Nonnull)file autoSave:(BOOL)flag
Parameters:
file
– File Object to be downloaded.autoSave
– BOOL. 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.
Note: Auto Saving option is applicable for Images and Video files only. The other file types need to be saved manually using Base64 encoded RAW data.
Callbacks at Receiver End:
-room:didFileDownloaded
: – Notification sent when the file has been downloaded with or without auto-saving.-room:didFileDownloadFailed:
– Notification sent when download fails.
[room downloadFile:fileObject autoSave:true]; // To receiver - File has been downloaded - (void)room:(EnxRoom *_Nonnull)room didFileDownloaded:(NSString *_Nullable)data { // Handle FileObject with download information } // To receiver - File download has failed - (void)room:(EnxRoom *_Nonnull)room didFileDownloadFailed:(NSArray *_Nullable)data { // 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: -(void)cancelUpload:(int)jobID
Parameter:
jobId
– 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: -(void)cancelAllUploads
– No Parameter required.
[EnxRoom cancelAllUploads];
Callback:
didFileUploadCancelled:
– Acknowledgment to the user when the file upload is canceled.
- (void)room:(EnxRoom *_Nonnull)room didFileUploadCancelled:(NSArray *_Nullable)data
Error Codes / Exceptions:
Code | Description |
5089 | Storage Access denied. |
5090 | Failed to save file. |
5091 | File-Sharing not available in this context. |
5092 | Too many files to upload. Max 1 file allowed per request. |
1185 | File size exceeds the max allowed size. |
1182 | Failed to upload file. |
5098 | Unable to cancel file upload after file upload complete. |
5099 | Failed to cancel upload as invalid Upload ID passed as a parameter. |
5100 | Failed to upload a possibly corrupt file. |
5102 | Cancel 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: -(void)cancelDownload:(int)jobID;
Parameter:
jobId
– 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: -(void)cancelAllDownloads
– No Parameter required.
[EnxRoom cancelAllDownloads];
Callback:
didFileDownloadCancelled:
– Acknowledgment to the user when the file download is canceled.
- (void)room:(EnxRoom *_Nonnull)room didFileDownloadCancelled:(NSArray *_Nullable)data;
Error Codes / Exceptions:
Code | Description |
5089 | Storage Access denied. |
5090 | Failed to save file. |
1183 | Failed to download file. |
1181 | File Download not available in this context |
5101 | File already downloaded. |