Send files
Attach files to messages to share information or improve collaboration.
Chat SDK supports multiple file attachments per message (unlike the Swift SDK). Each file must be 5 MB or less. Files upload sequentially, so consider implementing a progress indicator for better UX.
Requires File Sharing
Enable File Sharing in the Admin Portal and configure storage region and retention. Align file retention with Message Persistence retention.
Send files
Attach files to a draft message and publish using send().
Method signature
To add files, you must add elements to the files field ([InputFile]) of a MessageDraft object.
Sample code
Sample code
The code samples in Swift Chat SDK focus on asynchronous code execution.
You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.
Attach two files of different formats to a text message.
1
Get all message files
files returns all files attached to a message.
Method signature
This method has the following signature:
1message.files
Sample code
Sample code
The code samples in Swift Chat SDK focus on asynchronous code execution.
You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.
List all files attached to a message on the support channel.
1
Get all channel files
getFiles() returns all files attached to messages on a given channel.
Method signature
This method takes the following parameters:
1channel.getFiles(
2 limit: Int = 100,
3 next: String? = nil
4 ) async throws -> (files: [GetFileItem], page: PubNubHashedPage?)
Input
Output
(files: [GetFileItem], page: PubNubHashedPage?)#- Returned tuple containing these fields:
filesandpage. - property of (files: [GetFileItem], page: PubNubHashedPage?):
files# - Array containing file details.
- property of (files: [GetFileItem], page: PubNubHashedPage?):
page# - Pagination details.
- property of page:
next# - Random string returned from the server, indicating a specific position in a data set. Used for forward pagination, it fetches the next page, allowing you to continue from where you left off.
- property of page:
total# - Total number of files.
GetFileItem contains the following properties:
Sample code
Sample code
The code samples in Swift Chat SDK focus on asynchronous code execution.
You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.
List all files published on the support channel.
1
Delete files
deleteFile() removes files from PubNub storage.
Endpoint limitation
After deleting a file, you cannot identify which historical messages contained it.
Method signature
This method takes the following parameters:
1channel.deleteFile(
2 id: String,
3 name: String
4) async throws
Input
Output
Void#- Indicates that the operation completed successfully with no additional data.
Sample code
Sample code
The code samples in Swift Chat SDK focus on asynchronous code execution.
You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.
Remove a file named error-screenshot.png from the support channel.
1