-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: Bidirectional Blob Transfer API for Efficient Binary Data Transfer #8203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
riderx
wants to merge
15
commits into
ionic-team:main
Choose a base branch
from
riderx:blob-bi-way
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,784
−1
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…issing headers)), add notifications at app level for file download statuses and path
…ook initiated downloads for now (stream))
…le picker and duplex stream for javascript proxy write
…n implementation)
…inary data handling - Added `resolveWithBlob` methods in `PluginCall.java` to return binary data as blob URLs. - Introduced `getBlobData` method for fetching binary data from blob URLs. - Created `BlobStore` class in iOS to manage temporary blob storage with size limits and cleanup. - Implemented `CAPBlobURLSchemeHandler` to intercept and serve Capacitor blob URLs. - Enhanced `WebViewDelegationHandler` to allow blob URL requests. - Developed comprehensive unit tests for blob storage functionality in both Android and iOS. - Added support for additional fields in blob responses. - Ensured thread safety and proper handling of edge cases in blob storage operations.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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