You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
chore(dependencies): update websocket-driver to version 0.7.5 to fix vulnerability audit
This commit updates the websocket-driver dependency to version 0.7.5 in both pnpm-lock.yaml and pnpm-workspace.yaml to address security advisories. Additionally, the README.md for attachments-storage-react-native has been enhanced to clarify the functionality of local storage and streaming transport adapters, including usage examples and API details.
React Native file system storage adapters for [PowerSync](https://powersync.com) attachments.
8
+
React Native storage and transport adapters for [PowerSync](https://powersync.com) attachments.
9
9
10
-
This package provides `LocalStorageAdapter` implementations for React Native environments, allowing you to store and retrieve attachment files on device.
10
+
This package provides:
11
+
12
+
-**Local storage adapters** (`LocalStorageAdapter`) — persist attachment files on device.
13
+
-**Streaming transport adapters** (`AttachmentTransportAdapter`) — move attachment bytes directly between the local file and remote storage using native APIs, without buffering the whole file in JS memory. Recommended for large files (recordings, videos) on lower-end devices.
You'll also need to install one of the supported file system libraries:
25
+
You'll also need to install one of the supported file system libraries. The same library powers both the local storage adapter and the native transport adapter for that platform.
A transport adapter owns **all** remote operations (`upload` / `download` / `delete`) and transfers bytes natively — the file never enters the JS heap. When a `transportAdapter` is provided it fully replaces `remoteStorage` (which is no longer required); implement remote delete via the `deleteFile` callback.
72
89
73
-
Both adapters accept an optional `storageDirectory` parameter:
90
+
Both transports are backend-agnostic: you supply resolver callbacks that map an attachment to a request (typically a presigned URL from your backend).
91
+
92
+
### With Expo File System (`uploadAsync` / `downloadAsync`)
For files already written to disk (recordings, camera/picker output), use `AttachmentQueue.saveFileFromUri` to register them without reading the bytes into memory — the local adapter's `moveFile` relocates the file into managed storage.
155
+
156
+
```typescript
157
+
awaitattachmentQueue.saveFileFromUri({
158
+
localUri, // path to the existing file
159
+
fileExtension: 'm4a',
160
+
mediaType: 'audio/m4a'
161
+
});
77
162
```
78
163
79
164
## API
80
165
81
-
Both adapters implement the `LocalStorageAdapter` interface from `@powersync/common`:
166
+
### Local storage adapters
167
+
168
+
Implement the `LocalStorageAdapter` interface from `@powersync/common`:
82
169
83
170
-`initialize()` - Create the storage directory if it doesn't exist
84
171
-`clear()` - Remove all files from the storage directory
85
172
-`getLocalUri(filename)` - Get the full path for a filename
86
173
-`saveFile(filePath, data, options?)` - Save data to a file
87
174
-`readFile(filePath, options?)` - Read a file as ArrayBuffer
175
+
-`moveFile(sourceUri, targetUri)` - Move a file into managed storage without buffering (enables `saveFileFromUri`)
88
176
-`deleteFile(filePath)` - Delete a file
89
177
-`fileExists(filePath)` - Check if a file exists
90
178
-`makeDir(path)` - Create a directory
91
179
-`rmDir(path)` - Remove a directory
92
180
181
+
### Transport adapters
182
+
183
+
Implement the `AttachmentTransportAdapter` interface from `@powersync/common`:
184
+
185
+
-`upload(attachment)` - Transfer the local file to remote storage
186
+
-`download(attachment)` - Transfer the remote file into `attachment.localUri`
187
+
-`delete(attachment)` - Delete the file from remote storage
0 commit comments