Examples of syncing attachments between a client app and Supabase Storage.
Our React Native To-Do List demo app showcases how to sync attachments (such as photos) using the @powersync/attachments library, the PowerSync Service, and Supabase.
In this example, we are syncing photos, however other media types, such as PDFs, are also supported.
The library and this example implementation can be used as a reference for implementing similar functionality for a Postgres backend without Supabase.
The below assumes you have completed the steps outlined in the To-Do List app Readme. This includes installing and running the PowerSync React Native SDK; setting up a Supabase project; setting up a PowerSync instance and connecting it with Supabase.
In this demo app, Supabase Storage is used to store and serve attachments.
Finally, link this storage bucket to your app by opening up the AppConfig.ts file and adding the bucket name as the value to the supabaseBucket
key:
This concludes the necessary configuration for handling attachments in the To-Do List demo app. When running the app now, a photo can be taken for a to-do list item, and PowerSync will ensure that the photo syncs to Supabase and other devices (if sync rules allow).
Read on to learn more about how this works under the hood.
The @powersync/attachments library is used in conjunction with the PowerSync Service to sync photos. Refer to the library’s README for an overview of the main components. In summary, they are:
AttachmentRecord
to store the metadata of attachments.AttachmentState
to track the sync state of an AttachmentRecord
.AbstractAttachmentQueue
class to manage and sync AttachmentRecord
s:
AttachmentRecord
s.The UI of the demo app supports taking photos as follows:
expo-camera
to allow users to capture a photo.The app’s schema was modified to link a photo to a to-do item:
photo_id
was added as a column to the todos
table to link a photo to a to-do item.attachments
table is instantiated to store the metadata of photos.
The PhotoAttachmentQueue class extends the AbstractAttachmentQueue
abstract class and:
attachmentIds()
)AttachmentRecord
s to store photo metadata. (see newAttachmentRecord()
)savePhoto()
method to save photos into local storage and add them to the sync queue.Refer to this section in the library’s README to learn more about the various sync states and operations.
The following improvements can be considered for this implementation.
attachments
table and related schema.Our Flutter To-Do List demo app showcases how to sync attachments (such as photos) using our powersync_attachments_helper package for Flutter.
Our Kotlin To-Do List demo app showcases how to sync attachments using built-in attachments helpers.
Our Swift To-Do List demo app showcases how to sync attachments using built-in attachments helpers.
Examples of syncing attachments between a client app and Supabase Storage.
Our React Native To-Do List demo app showcases how to sync attachments (such as photos) using the @powersync/attachments library, the PowerSync Service, and Supabase.
In this example, we are syncing photos, however other media types, such as PDFs, are also supported.
The library and this example implementation can be used as a reference for implementing similar functionality for a Postgres backend without Supabase.
The below assumes you have completed the steps outlined in the To-Do List app Readme. This includes installing and running the PowerSync React Native SDK; setting up a Supabase project; setting up a PowerSync instance and connecting it with Supabase.
In this demo app, Supabase Storage is used to store and serve attachments.
Finally, link this storage bucket to your app by opening up the AppConfig.ts file and adding the bucket name as the value to the supabaseBucket
key:
This concludes the necessary configuration for handling attachments in the To-Do List demo app. When running the app now, a photo can be taken for a to-do list item, and PowerSync will ensure that the photo syncs to Supabase and other devices (if sync rules allow).
Read on to learn more about how this works under the hood.
The @powersync/attachments library is used in conjunction with the PowerSync Service to sync photos. Refer to the library’s README for an overview of the main components. In summary, they are:
AttachmentRecord
to store the metadata of attachments.AttachmentState
to track the sync state of an AttachmentRecord
.AbstractAttachmentQueue
class to manage and sync AttachmentRecord
s:
AttachmentRecord
s.The UI of the demo app supports taking photos as follows:
expo-camera
to allow users to capture a photo.The app’s schema was modified to link a photo to a to-do item:
photo_id
was added as a column to the todos
table to link a photo to a to-do item.attachments
table is instantiated to store the metadata of photos.
The PhotoAttachmentQueue class extends the AbstractAttachmentQueue
abstract class and:
attachmentIds()
)AttachmentRecord
s to store photo metadata. (see newAttachmentRecord()
)savePhoto()
method to save photos into local storage and add them to the sync queue.Refer to this section in the library’s README to learn more about the various sync states and operations.
The following improvements can be considered for this implementation.
attachments
table and related schema.Our Flutter To-Do List demo app showcases how to sync attachments (such as photos) using our powersync_attachments_helper package for Flutter.
Our Kotlin To-Do List demo app showcases how to sync attachments using built-in attachments helpers.
Our Swift To-Do List demo app showcases how to sync attachments using built-in attachments helpers.