Share media such as images, videos and files with users in a chat room. Upload the media to your own storage service, such as AWS S3, and then use theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/ably/docs/llms.txt
Use this file to discover all available pages before exploring further.
metadata field to reference the location of the media when a user sends a message. On the receiving end, display the media to subscribers that received the message.
Access control
Ensure that you add a layer of authentication server-side if the media shouldn’t be publicly available. Do not add signed URLs to the messagemetadata because everyone who receives the message will have access to it. Additionally, signed URLs typically have expiration dates and chat messages may be stored for longer.
If you serve the media directly from a service, such as AWS S3, consider saving a file name in the metadata of the message. Then use a mechanism for the user to request a signed URL to the file.
Upload media
Users need to be able to choose which media to attach to their message in your app. Write an upload function and make it available in the chat app context. You can use either a unique identifier for the media, or a URL to its location. Ensure that any identifier is unique and that URLs are validated when they are received. The following is an example of an upload function:uploadMedia() flow to save the resulting object. In your UI, the mediaToAttach array should be displayed so that users can see which media will be attached to their message. It also enables users to add or remove selected media.
Send a message
Once a user has attached their media to the message, use themetadata field of the message to store its reference. metadata is a key-value object that can also be used to associate additional information such as its title and dimensions.
Display media to subscribers
When a message is received that contains media, you need to display it in your app. Firstly, make sure that you validate themetadata. If you are using IDs then ensure they are in the correct format, or if using URLs then validate the schema, domain, path and query parameters are as expected.
Define a function to get the valid media from a message:
Add media to an existing message
You can also add media to an existing message by editing itsmetadata:
Remove media from an existing message
You can remove media from an existing message by updating itsmetadata:
Media moderation
Ably moderation feature is currently limited to text moderation. To add automatic or human moderation for media, you’ll need to implement moderation server-side. An example flow for this would be:Send message
Send a message with the
metadata containing information about the media; either an ID or URL.metadata field of the message to reflect its moderation status.