Skip to content

Latest commit

 

History

History
102 lines (72 loc) · 2.88 KB

File metadata and controls

102 lines (72 loc) · 2.88 KB

@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-native

You'll also need to install one of the supported file system libraries:

For Expo projects

Important

Requires Expo 54+

npx expo install expo-file-system

For bare React Native projects

npm install @dr.pogodin/react-native-fs

Usage

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 exist
  • clear() - Remove all files from the storage directory
  • getLocalUri(filename) - Get the full path for a filename
  • saveFile(filePath, data, options?) - Save data to a file
  • readFile(filePath, options?) - Read a file as ArrayBuffer
  • deleteFile(filePath) - Delete a file
  • fileExists(filePath) - Check if a file exists
  • makeDir(path) - Create a directory
  • rmDir(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