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
| Parameter | Description |
|---|---|
limitType: IntDefault: 100 | Number of files to return. |
nextType: StringDefault: n/a | String token to get the next batch of files. |
Output
| Parameter | Description |
|---|---|
(files: [GetFileItem], page: PubNubHashedPage?)Type: object | Returned tuple containing these fields: files and page. |
→ filesType: [GetFileItem] | Array containing file details. |
→ pageType: PubNubHashedPage | Pagination details. |
→ → nextType: String | 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. |
→ → totalType: Int | Total number of files. |
GetFileItem contains the following properties:
| Parameter | Description |
|---|---|
nameType: String | Name of the file, like error-1.jpg. |
idType: String | Unique identifier assigned to the file by PubNub, like 736499374. |
urlType: String | File's direct downloadable URL, like https://ps.pndsn.com/v1/files/demo/channels/support/files/736499374/error-1.jpg. |
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
| Parameter | Description |
|---|---|
id *Type: StringDefault: n/a | Unique identifier assigned to the file by PubNub. |
name *Type: StringDefault: n/a | Name of the file. |
Output
| Parameter | Description |
|---|---|
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