Link Search Menu Expand Document

File Upload

Table of contents


This article will help you to support file upload.

You can checkout an implementation example here.

Enable file transfer in the admin console.

  1. Open and log in.
  2. Go to CHANNELS -> Chat -> Chat Windows -> Choose relevant window -> File Transfer section.
  3. Check Enable and choose: Agent to customer , Customer to agent.


Using Default File Upload Button

Register To Delegate

override func viewDidLoad() {
    chatController.delegate = self

Implement Delegate Upload Trigger Event

In order to be notified when the user triggered the upload, you need to implement didClickUploadFile in ChatControllerDelegate.

extension FileUploadDemoViewController: ChatControllerDelegate {
    func didClickUploadFile() {
        // present file picker

Creating Upload Request

Once the file was picked create an upload request.

let request = UploadRequest()
request.fileName = (resources.first!).originalFilename
request.fileType = .picture
request.fileData = data

Uploading Files

///  Once upload request created start upload file process.
self.chatController.uploadFile(request, progress: { (progress) in
    /// You can get progress values, to show upload progress bar.
    print("application file upload progress -> %.5f", progress)
}) { (info: FileUploadInfo!) in
    /// Call handle function on ChatController with upload file information.
    // self.uploadBtn.removeFromSuperview() uncomment for custom file upload

Using Custom File Upload Button

To implement your own File Upload button: Listen to the relevant chat state (.pending) by implementing didUpdateState in ChatControllerDelegate.

extension FileUploadDemoViewController: ChatControllerDelegate {
    func didUpdateState(_ event: ChatStateEvent!) {
        switch event.state {
        ///a. Listen to relevant chat state
        case .pending:
            /// b. Validate file transfer enabled on bold admin console.
            if(self.chatController.isFileTransferEnabled) {
                /// c. Add custom button.
                DispatchQueue.main.async {
                    self.uploadBtn.backgroundColor = .blue
                    self.uploadBtn.setTitle("Upload File", for: .normal)
                    self.uploadBtn.frame.size = CGSize(width: 150, height: 70)
           = (self.navigationController?.visibleViewController?!
                    self.uploadBtn.addTarget(self, action: #selector(self.uploadFile), for: .touchUpInside)

Note: File upload must be enabled in the admin console.