@uploadista/react-native-core
v0.1.1-beta.2
Published
Core React Native client for Uploadista
Downloads
2,501
Readme
@uploadista/react-native
React Native client for Uploadista with mobile-optimized upload patterns and support for both Expo-managed and bare React Native environments.
Overview
@uploadista/react-native provides a first-class React Native integration for Uploadista, enabling seamless file uploads and flow management on iOS and Android. The client abstracts platform differences and provides idiomatic React Native patterns for:
- Single file uploads - Upload one file with progress tracking
- Multi-file uploads - Concurrent uploads with batch management
- Flow uploads - Orchestrated uploads through processing pipelines
- Camera uploads - Direct camera capture and upload
- Gallery uploads - Photo/video library selection and upload
- File picker uploads - Generic document selection
Features
- ✅ Expo and Bare RN Support - Works with both Expo-managed and bare React Native workflows
- ✅ iOS & Android - Full support for iOS 14+ and Android 7+
- ✅ File System Abstraction - Pluggable providers for different environments
- ✅ Mobile Patterns - Camera, gallery, and file picker integrations
- ✅ Progress Tracking - Real-time upload progress and metrics
- ✅ WebSocket Support - Flow uploads with real-time events
- ✅ Type Safe - Full TypeScript support with strict typing
- ✅ Zero External Dependencies - Only optional peer dependencies
Installation
Prerequisites
- React Native 0.71+
- React 16.8+ (for hooks)
- Either Expo SDK 51+ or bare React Native environment
NPM Installation
npm install @uploadista/react-native @uploadista/client @uploadista/coreYarn Installation
yarn add @uploadista/react-native @uploadista/client @uploadista/corepnpm Installation
pnpm add @uploadista/react-native @uploadista/client @uploadista/coreQuick Start
Expo Setup
For Expo managed projects, install the required Expo modules:
expo install expo-document-picker expo-image-picker expo-camera expo-file-systemThen in your app:
import { UploadistaProvider } from '@uploadista/react-native';
import { UploadClient } from '@uploadista/client';
const client = new UploadClient({
apiUrl: 'https://api.example.com',
});
export default function App() {
return (
<UploadistaProvider client={client}>
<YourAppContent />
</UploadistaProvider>
);
}Bare React Native Setup
For bare React Native, install native dependencies:
npm install react-native-document-picker react-native-image-picker rn-fetch-blob
# For iOS
cd ios && pod install && cd ..
# For Android (usually automatic)Then configure the provider:
import { UploadistaProvider } from '@uploadista/react-native';
import { NativeFileSystemProvider } from '@uploadista/react-native/providers';
import { UploadClient } from '@uploadista/client';
const client = new UploadClient({
apiUrl: 'https://api.example.com',
});
const fileSystemProvider = new NativeFileSystemProvider();
export default function App() {
return (
<UploadistaProvider
client={client}
fileSystemProvider={fileSystemProvider}
>
<YourAppContent />
</UploadistaProvider>
);
}Basic Usage
Single File Upload
import { useUploadistaClient } from '@uploadista/react-native';
export function SingleUploadScreen() {
const { fileSystemProvider } = useUploadistaClient();
const handlePickAndUpload = async () => {
try {
// Pick a file
const file = await fileSystemProvider.pickDocument();
// Read file content
const content = await fileSystemProvider.readFile(file.uri);
// Upload to server
const response = await fetch('https://api.example.com/upload', {
method: 'POST',
body: content,
headers: {
'Content-Type': file.mimeType || 'application/octet-stream',
},
});
console.log('Upload successful:', await response.json());
} catch (error) {
console.error('Upload failed:', error);
}
};
return (
<Button
title="Pick and Upload File"
onPress={handlePickAndUpload}
/>
);
}Camera Upload
import { useUploadistaClient } from '@uploadista/react-native';
export function CameraUploadScreen() {
const { fileSystemProvider } = useUploadistaClient();
const handleCaptureAndUpload = async () => {
try {
// Capture photo with camera
const photo = await fileSystemProvider.pickCamera();
// Upload to server
const formData = new FormData();
formData.append('file', {
uri: photo.uri,
name: photo.name,
type: photo.mimeType || 'image/jpeg',
} as any);
const response = await fetch('https://api.example.com/upload', {
method: 'POST',
body: formData,
});
console.log('Photo uploaded:', await response.json());
} catch (error) {
console.error('Upload failed:', error);
}
};
return (
<Button
title="Capture and Upload Photo"
onPress={handleCaptureAndUpload}
/>
);
}File System Provider
The file system abstraction layer allows you to work with files uniformly across Expo and bare React Native:
interface FileSystemProvider {
// Select a document
pickDocument(options?: PickerOptions): Promise<FilePickResult>;
// Select an image from gallery
pickImage(options?: PickerOptions): Promise<FilePickResult>;
// Select a video from gallery
pickVideo(options?: PickerOptions): Promise<FilePickResult>;
// Capture a photo with camera
pickCamera(options?: CameraOptions): Promise<FilePickResult>;
// Read file as ArrayBuffer
readFile(uri: string): Promise<ArrayBuffer>;
// Get file information
getFileInfo(uri: string): Promise<FileInfo>;
// Convert file path to accessible URI
getDocumentUri(filePath: string): Promise<string>;
}Types
FilePickResult
Result from file picker operations:
interface FilePickResult {
uri: string; // File URI (platform-specific)
name: string; // File name with extension
size: number; // File size in bytes
mimeType?: string; // MIME type (if available)
localPath?: string; // Local file path (if available)
}FileInfo
Information about a file:
interface FileInfo {
uri: string; // File URI
name: string; // File name
size: number; // File size in bytes
mimeType?: string; // MIME type (if available)
modificationTime?: number; // Last modified timestamp
}PickerOptions
Options for file picker operations:
interface PickerOptions {
allowedTypes?: string[]; // MIME types to filter
allowMultiple?: boolean; // Allow multiple selection
maxSize?: number; // Maximum file size in bytes
}Permissions
iOS
Add to Info.plist:
<key>NSCameraUsageDescription</key>
<string>We need camera access to upload photos</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>We need photo library access to upload images</string>Android
Add to AndroidManifest.xml:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />The file system providers handle runtime permission requests automatically.
Architecture
Expo Provider
Uses Expo's native modules for file system access:
expo-document-picker- Document selectionexpo-image-picker- Image and video selection from galleryexpo-camera- Camera integrationexpo-file-system- File reading
Native Provider
Uses third-party native modules for bare React Native:
react-native-document-picker- Document selectionreact-native-image-picker- Image and video selectionrn-fetch-blob- File system and network operations
Both providers implement the same FileSystemProvider interface, allowing you to write code once and run everywhere.
Examples
See the examples/ directory for complete working examples:
react-native-expo-client/- Expo managed workflow examplereact-native-cli-client/- Bare React Native example
Development
Building
npm run buildType Checking
npm run type-checkLinting
npm run lintTesting
npm testAPI Reference
createFileSystemProvider()
Creates a file system provider based on configuration:
import { createFileSystemProvider } from '@uploadista/react-native/providers';
// Auto-detect environment
const provider = createFileSystemProvider();
// Specify Expo
const expoProvider = createFileSystemProvider({ type: 'expo' });
// Specify native
const nativeProvider = createFileSystemProvider({ type: 'native' });
// Use custom provider
const customProvider = createFileSystemProvider({
provider: myCustomProvider,
});getDefaultFileSystemProvider()
Gets the automatically detected file system provider for the current environment:
import { getDefaultFileSystemProvider } from '@uploadista/react-native/providers';
const provider = getDefaultFileSystemProvider();Troubleshooting
Module not found errors
Ensure you've installed the required modules for your environment:
Expo:
expo install expo-document-picker expo-image-picker expo-camera expo-file-systemBare RN:
npm install react-native-document-picker react-native-image-picker rn-fetch-blobPermission denied
Check that:
- Permissions are declared in
Info.plist(iOS) orAndroidManifest.xml(Android) - User has granted permissions at runtime (app will request automatically)
- For Android 13+, ensure
READ_MEDIA_IMAGESandREAD_MEDIA_VIDEOare also declared
File picker not opening
Verify that:
- You're inside a valid React component
- The provider is properly initialized
- You're calling from a user interaction (not from render)
Support
For issues and questions:
- GitHub Issues: https://github.com/uploadista/uploadista/issues
- Documentation: https://uploadista.dev/docs
License
MIT - See LICENSE file for details
