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
dataStreamStream of file bytes.
fileExtensionstringFile extension (e.g.
"jpg") used to derive the filename.mediaTypestringOptional MIME type.
metaDatastringOptional opaque metadata persisted with the attachment row.
idstringOptional explicit attachment id; a UUID is generated when not supplied.
updateHookFunc<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.