Skip to content

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

Open
sonalidudhia wants to merge 2 commits into
NativePHP:mainfrom
sonalidudhia:fix/issue-8-camera-path-accessibility
Open

Fix: Use PHP-accessible, persistent storage for captured media (Android + iOS)#12
sonalidudhia wants to merge 2 commits into
NativePHP:mainfrom
sonalidudhia:fix/issue-8-camera-path-accessibility

Conversation

@sonalidudhia

Copy link
Copy Markdown

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

1 participant