fix: use unique filename per image in gallery fallback path#16
Merged
andredestro merged 2 commits intomainfrom Apr 28, 2026
Merged
fix: use unique filename per image in gallery fallback path#16andredestro merged 2 commits intomainfrom
andredestro merged 2 commits intomainfrom
Conversation
OS-pedrogustavobilro
approved these changes
Apr 28, 2026
Contributor
OS-pedrogustavobilro
left a comment
There was a problem hiding this comment.
Left a remark, but may not need changes in your PR (unless you disagree). Approved 🤌
| val buffer = ByteArray(8 * 1024) | ||
| val extension = MimeTypeMap.getSingleton().getExtensionFromMimeType(mimeType) ?: "dat" | ||
| val targetFile = createCaptureFile(context, "file.${extension}") | ||
| val targetFile = createCaptureFile(context, "${UUID.randomUUID()}.${extension}") |
Contributor
There was a problem hiding this comment.
While this seems to fix the issue, it brings up the situation of the cache size growing with the amount of files being returned from the gallery. But that also applies to the photos taken with camera.
Unlike iOS, the cached images are not cleared on app restart, only the videos.
That's possibly a discrepancy we should address one day, but guess this PR may not be the place for it (unless you disagree).
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
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.
Problem
When selecting multiple images from the gallery on certain Android devices (confirmed: Samsung Galaxy S10 / Android 12 / One UI 4.2), all results returned the same
uriandwebPath:/data/user/0/com.app/cache/file.jpgThis happened because
getRealPath()returnsnullfor photo picker URIs on devices where the_dataMediaStore column is unavailable (deprecated in Android 10+ scoped storage). The fallbackdownloadCacheFileFromInputStreamwas then used, writing every selected image to the same hardcoded filename"file.<extension>"— each image overwriting the previous one.Fixes: ionic-team/capacitor-camera#47
Fix
Replace the hardcoded filename with a
UUID-based unique name indownloadCacheFileFromInputStream, ensuring each selected image gets its own distinct cache file.