Table of Contents

Method SaveFileAsync

Namespace
PowerSync.Common.Attachments
Assembly
PowerSync.Common.dll

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.

public Task<Attachment> SaveFileAsync(Stream data, string fileExtension, string? mediaType = null, string? metaData = null, string? id = null, Func<ITransaction, Attachment, Task>? updateHook = null)

Parameters

data Stream

Stream of file bytes.

fileExtension string

File extension (e.g. "jpg") used to derive the filename.

mediaType string

Optional MIME type.

metaData string

Optional opaque metadata persisted with the attachment row.

id string

Optional explicit attachment id; a UUID is generated when not supplied.

updateHook Func<ITransaction, Attachment, Task>

Optional callback executed in the same write transaction as the attachment INSERT. Use this to atomically link the new attachment to your data model.

Returns

Task<Attachment>

The created attachment record (with stamped Timestamp and Size).

Remarks

A updateHook is provided which should be used when assigning relationships to the newly created attachment. This hook is executed in the same write transaction which creates the attachment record.