Class AttachmentQueue
- Namespace
- PowerSync.Common.Attachments
- Assembly
- PowerSync.Common.dll
Manages the lifecycle and synchronization of attachments between local and remote storage. Provides automatic synchronization, upload/download queuing, attachment monitoring, verification and repair of local files, and cleanup of archived attachments.
public sealed class AttachmentQueue : IAsyncDisposable
- Inheritance
-
AttachmentQueue
- Implements
- Inherited Members
Constructors
Methods
- ClearQueueAsync()
Clears the attachment queue and deletes all attachment files from local storage.
- DeleteFileAsync(string, Func<ITransaction, Attachment, Task>?)
Marks an existing attachment for deletion. The remote and local files are removed asynchronously on the next sync pass.
- DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
- ExpireCacheAsync()
Removes archived attachments that exceed ArchivedCacheLimit, along with their local files. Archived rows up to the limit are kept as a cache so that briefly re-referenced attachments can be restored without a re-download.
- SaveFileAsync(Stream, string, string?, string?, string?, Func<ITransaction, Attachment, Task>?)
Saves a file to local storage and queues it for upload to remote storage. The file bytes are written to local storage immediately; the upload happens asynchronously on the next sync pass.
- StartSyncAsync()
Starts the attachment synchronization process.
- StopSyncAsync()
Stops the attachment synchronization process. Cancels the sync pipeline, stops the periodic timer, and tears down all attachment watchers. Waits for any in-flight upload/download/delete to finish. Syncing can be resumed by calling StartSyncAsync() again.
- SyncStorageAsync()
Synchronizes all active attachments between local and remote storage. Uploads pending files, downloads newly referenced ones, applies pending deletes, and prunes archived rows.
- TriggerSync()
Requests a sync pass to run as soon as possible. Useful from error handlers ("retry now") or UI ("sync now"). Coalesces with any in-flight or pending sync; safe to call rapidly.
- VerifyAttachmentsAsync()
Verifies the integrity of all attachment records and repairs inconsistencies. Checks each attachment record against the local filesystem and:
- Updates LocalUri if the file exists at a different path.
- Archives non-Synced attachments whose local files are missing.
- Requeues synced attachments for download if their local files are missing.