Custom File Upload Handler
How to upload files to a third party host or server
In certain circumstances, the Chat SDK needs to be able to upload files to an external server. Those situations are the following:
- Uploading the user's profile image 
- Uploading thread images 
- Sending image messages 
File upload is decoupled from the main project and is handled by the UploadHandler service.
In order to customize the upload behavior or upload files to a custom server, it's necessary to create a new upload handler service and then register it with the Chat SDK framework.
The Upload Handler
To make a new upload handler you will need to subclass the AbstractUploadHandler for Android or the BAbstractUploadHandler for iOS.
The upload handler only has one method that needs to be implemented:
Observable<FileUploadResult> uploadFile(byte[] data, String name, String mimeType);-(RXPromise *) uploadFile:(NSData *)file withName: (NSString *) name mimeType: (NSString *) mimeType;iOS
To create a custom upload handler, you need to do the following:
- Create a new subclass of the - BAbstractUploadHandlerclass.
- Implement the following method: - -(RXPromise *) uploadFile:(NSData *)file withName: (NSString *) name mimeType: (NSString *) mimeType;
- Register your new upload handler with the framework. In your App Delegate after you have called - BChatSDK.initializeadd the following line of code:- BChatSDK.shared.networkAdapter.upload = [[YourUploadHandler alloc] init]
To see an example of how to implement the function, it's recommended to look at the BFirebaseUploadHandler class which demonstrates a model implementation for Google File Storage.
Android
To create a custom upload handler, you need to do the following:
- Create a new subclass of the - AbstractUploadHandlerclass.
- Implement the following method: - Observable<FileUploadResult> uploadFile(byte[] data, String name, String mimeType);
- Register your new upload handler with the framework. After you have called - ChatSDK.initializeadd the following line of code:- ChatSDK.shared().a().upload = [[YourUploadHandler alloc] init]
To see an example of how to implement the function, it's recommended to look at the FirebaseUploadHandler class which demonstrates a model implementation for Google File Storage.
Last updated
Was this helpful?