feat: Bidirectional Blob Transfer API for Efficient Binary Data Transfer #8203
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR introduces a bidirectional blob transfer system that enables efficient binary data transfer between native code and JavaScript without base64 encoding overhead. This provides ~99% reduction in bridge traffic for large binary data like images, videos, and files.
Motivation
Currently, Capacitor transfers binary data via base64 encoding, which:
This PR was inspired by capacitor-blob-writer but improves upon it by integrating directly into the core framework.
Features
1. Native → JavaScript (Return Blobs from Plugins)
iOS:
Android:
JavaScript:
2. JavaScript → Native (Send Blobs to Plugins)
JavaScript:
iOS:
Android:
Implementation Details
Core Components
iOS:
Android:
Blob URL Format
```
blob:capacitor://
```
Example: `blob:capacitor://a3d5e7f9-1234-5678-90ab-cdef12345678`
Automatic Source Detection
The system automatically handles:
Memory Management
Security
Performance Comparison
Before (Base64)
```
1MB binary → 1.33MB base64 string → JavaScript
```
After (Blob Transfer)
```
1MB binary → ~50 byte URL → JavaScript
```
Result: ~99% reduction in bridge traffic
Testing
Comprehensive test suites included:
iOS: `BlobStoreTests.swift` (20+ tests)
Android: `BlobStoreTest.java` (20+ tests)
Documentation
Complete API documentation in `BLOB_TRANSFER_API.md`:
Backward Compatibility
✅ Fully backward compatible
Files Changed
New Files (7)
Modified Files (2)
Use Cases
Perfect for plugins handling:
Example Plugins That Would Benefit
Migration Example
Before
After
Next Steps
To complete integration:
Related