Skip to content

Fix: Use PHP-accessible, persistent storage for captured media (Android + iOS) - #12

Merged
simonhamp merged 3 commits into
NativePHP:mainfrom
sonalidudhia:fix/issue-8-camera-path-accessibility
Sep 5, 2026
Merged

simonhamp merged 3 commits into
NativePHP:mainfrom
sonalidudhia:fix/issue-8-camera-path-accessibility

Conversation

@sonalidudhia

Copy link
Copy Markdown
Contributor

Fixes #8

Problem

On Android, PhotoTaken returned a path inside context.cacheDir (/data/user/0/<pkg>/cache/...) that PHP could not read via file_exists()/file_get_contents().

Fix

  • Android: photo, video, and gallery captures now save to context.filesDir/Camera and context.filesDir/Gallery instead of cacheDir.
  • iOS: same class of risk existed via NSTemporaryDirectory(), which iOS can purge at any time. Captures now save to Application Support/Camera and /Gallery instead, matching Android's persistent-storage approach. isExcludedFromBackup is preserved so backups aren't bloated.

Testing

Verified on a Laravel/NativePHP app (Android emulator + physical device): captured photo path now resolves under files/Camera/..., and file_exists(), file_get_contents(), and Storage::put() all succeed against the returned path.

NativePHP added 2 commits August 24, 2026 12:14
- Changed photo capture to save to context.filesDir/Camera instead of context.cacheDir
- Updated video recording to use the same accessible directory
- Updated gallery picker (single and multiple) to save to context.filesDir/Gallery
- This fixes the issue where PhotoTaken event returned paths in private Android cache
  that PHP cannot access (e.g., /data/user/0/com.domain.app/cache/)
- Now PHP can properly read captured photos and videos using file_get_contents()
  and Storage::put() operations

Fixes NativePHP#8
- Photo, video, and gallery captures now save to Application Support/Camera
  and Application Support/Gallery instead of NSTemporaryDirectory()
- NSTemporaryDirectory() can be purged by iOS at any time (low disk space,
  relaunch, etc), risking the same class of 'file went missing before PHP
  could read it' failure as Android's cache dir (Issue NativePHP#8)
- Application Support is private and persistent (never auto-purged),
  matching the fix already applied on Android (cacheDir -> filesDir)
- isExcludedFromBackup is unaffected -- captures still won't bloat
  iCloud/iTunes backups

Related to NativePHP#8
@simonhamp
simonhamp merged commit 9e9e7c8 into NativePHP:main Sep 5, 2026
2 checks passed
simonhamp added a commit that referenced this pull request Oct 22, 2026
Since #12, captures and gallery picks live in persistent app storage
instead of cache/temp. On Android that was filesDir, which Auto Backup
copies to Google Drive in a stock NativePHP app. On iOS the gallery copy
path never set isExcludedFromBackup, so picked files went to iCloud.

Android now writes to noBackupFilesDir, which is persistent and never
backed up. iOS sets isExcludedFromBackup on gallery files like the photo
and video paths already do.

The storage docs were stale, so they now list the real folders and tell
apps to copy what they need and delete the original, since the plugin
never cleans these up.

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: PhotoTaken returns inaccessible Android path

2 participants