@powersync/attachments-storage-react-native
v0.0.2
Published
React Native file system storage adapters for PowerSync attachments
Downloads
994
Readme
@powersync/attachments-storage-react-native
[!NOTE] Attachment helpers are currently in an alpha state, intended strictly for testing. Expect breaking changes and instability as development continues.
Do not rely on this package for production use.
React Native file system storage adapters for PowerSync attachments.
This package provides LocalStorageAdapter implementations for React Native environments, allowing you to store and retrieve attachment files on device.
Installation
npm install @powersync/attachments-storage-react-native
# or
pnpm add @powersync/attachments-storage-react-native
# or
yarn add @powersync/attachments-storage-react-nativeYou'll also need to install one of the supported file system libraries:
For Expo projects
[!IMPORTANT] Requires Expo 54+
npx expo install expo-file-systemFor bare React Native projects
npm install @dr.pogodin/react-native-fsUsage
With Expo File System
import { ExpoFileSystemStorageAdapter } from '@powersync/attachments-storage-react-native';
import { AttachmentQueue } from '@powersync/react-native';
const storageAdapter = new ExpoFileSystemStorageAdapter();
const attachmentQueue = new AttachmentQueue({
powersync: db,
storage: cloudStorage,
storageAdapter
});With React Native FS
import { ReactNativeFileSystemStorageAdapter } from '@powersync/attachments-storage-react-native';
import { AttachmentQueue } from '@powersync/react-native';
const storageAdapter = new ReactNativeFileSystemStorageAdapter();
const attachmentQueue = new AttachmentQueue({
powersync: db,
storage: cloudStorage,
storageAdapter
});Custom Storage Directory
Both adapters accept an optional storageDirectory parameter:
const storageAdapter = new ExpoFileSystemStorageAdapter('/custom/path/to/attachments/');API
Both adapters implement the LocalStorageAdapter interface from @powersync/common:
initialize()- Create the storage directory if it doesn't existclear()- Remove all files from the storage directorygetLocalUri(filename)- Get the full path for a filenamesaveFile(filePath, data, options?)- Save data to a filereadFile(filePath, options?)- Read a file as ArrayBufferdeleteFile(filePath)- Delete a filefileExists(filePath)- Check if a file existsmakeDir(path)- Create a directoryrmDir(path)- Remove a directory
Supported Versions
| Adapter | Library | Supported Versions |
| ------------------------------------- | ----------------------------- | ------------------ |
| ExpoFileSystemStorageAdapter | expo-file-system | >=19.0.0 (Expo 54+)|
| ReactNativeFileSystemStorageAdapter | @dr.pogodin/react-native-fs | ^2.25.0 |
License
Apache-2.0
